public class FileDemo {
public static void main(String[] args) {
File file = new File("E:\\abc");
System.out.println(file.getName());
treeWalk(file, 1);
}
public static void treeWalk(File dir, int level) {
String preStr = "";
for (int i = 0 ; i < level; i ++) {
preStr += " ";
}
File[] files = dir.listFiles();
for(int i = 0; i < files.length; i++) {
System.out.println(preStr + files[i].getName());
if(files[i].isDirectory()) {
treeWalk(files[i], level+1);
}
}
}
}
时间: 2024-12-09 02:57:57