ComenzarEmpieza gratis

Organizar notas en una carpeta

Para mantener todo ordenado, tu app debería guardar las notas en una carpeta dedicada. En este ejercicio, crearás un directorio llamado "notes" e imprimirás su ruta. Así podrás mantener juntos los archivos relacionados y encontrarlos fácilmente.

Este ejercicio forma parte del curso

Entrada/Salida y Streams en Java

Ver curso

Instrucciones del ejercicio

  • Crea un objeto File llamado notesDir que apunte a notes.
  • Crea el directorio llamado notes en el sistema.
  • Obtén la ruta relativa del directorio llamado notes.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

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());
        }
    }
}
Editar y ejecutar código