Get startedGet started for free

Organizing notes into a folder

To keep things tidy, your app should save notes in a dedicated folder. In this exercise, you’ll create a directory called "notes" and print its path. This lets you keep related files together and easy to find.

This exercise is part of the course

Input/Output and Streams in Java

View Course

Exercise instructions

  • Create a File object notesDir that points to notes.
  • Create the directory named notes in the system.
  • Retrieve the relative path of the directory named notes.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

import java.io.File;

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());
        }
    }
}
Edit and Run Code