I'm doing a program creating, modifying and scrolling directorios
and archivos
, I'm stuck in the part of showing on the screen the content of a directorio
and in the case of having sub-directorios
show what these they have.
Code that I use to show what is inside a directorio
.
public static void caso6() {
System.out.println("Indica la ruta del direcotrio: ");
String ruta = keyboard.nextLine();
File rutaArchivo = new File(ruta);
if (rutaArchivo.exists()) {
String[] archivos = rutaArchivo.list();
if (archivos == null) {
System.out.println("No hay ficheros en el directorio especificado");
} else {
for (int x = 0; x < archivos.length; x++) {
System.out.println(archivos[x]);
}
}
} else {
System.out.println("El directori o la ruta no existen.");
}
}