メモをフォルダに整理する
アプリで整理しやすくするため、メモは専用のフォルダに保存します。この演習では、"notes" というディレクトリを作成し、そのパスを出力します。関連するファイルをまとめて管理し、見つけやすくできます。
この演習はコースの一部です
Java の入出力とストリーム
演習の手順
notesを指すFileオブジェクトnotesDirを作成します。- システム上に
notesという名前のディレクトリを作成します。 notesディレクトリの相対パスを取得します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
class DirectoryManager {
public static void main(String[] args) {
try {
// Create a File object to represent the directory
File notesDir = ____ _____("notes");
// Create a directory in the system
if (____.____()) {
System.out.println("Directory 'notes' created successfully");
}
// Retrieve and print the relative path of the directory
System.out.println("Relative Path: " + ____.____());
} catch (Exception e) {
System.out.println("An error occurred: " + e.getMessage());
}
}
}