始める無料で始める

メモをフォルダに整理する

アプリで整理しやすくするため、メモは専用のフォルダに保存します。この演習では、"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());
        }
    }
}
コードを編集して実行