Browse Source

Pongo el tabulado y las rayas, implemento que se pueda meter una Ruta

por pantalla
master
vigliom 2 years ago
parent
commit
d196578e7e
2 changed files with 28 additions and 18 deletions
  1. BIN
      bin/jorpelu/com/Tree.class
  2. +28
    -18
      src/jorpelu/com/Tree.java

BIN
bin/jorpelu/com/Tree.class View File


+ 28
- 18
src/jorpelu/com/Tree.java View File

@ -1,27 +1,37 @@
package jorpelu.com;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Tree {
public static void main(String[] args) throws IOException {
printFile(new File("."), "");
}
printFile(pideRuta(), "");
}
public static File pideRuta() {
System.out.println("Introduzca una ruta a analizar: ");
Scanner sc = new Scanner(System.in);
File f = null;
try {
f = new File(sc.next());
} catch (Exception e) {
e.setStackTrace(e.getStackTrace());
}
sc.close();
return f;
}
public static void printFile(File f, String spaces) {
System.out.println(spaces.concat(File.separator).concat(f.getName()));
if (f.isDirectory() && f.canRead()) {
for (File file : f.listFiles()) {
System.out.print("|");
printFile(file, spaces.concat("__"));
}
}
}
System.out.println(spaces.concat("|____").concat(f.getName()));
if (f.isDirectory() && f.canRead()) {
for (File file : f.listFiles()) {
printFile(file, spaces.concat(" "));
}
}
}
}

Loading…
Cancel
Save