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
Instrucciones del ejercicio
- Crea un objeto
FilellamadonotesDirque apunte anotes. - Crea el directorio llamado
notesen 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());
}
}
}