通过递归按照树形图输出所有文件
public class ListAll {
public static void main(String[] args) {
new ListAll().listAll(new File("D:\\test"), 0);
}
public void listAll(File file, int depth) {
for(int i = 0; i < depth; i++) {
System.out.print("\t");
}
System.out.println(file.getName());
if (file.isDirectory()) {
for (File subFile : file.listFiles()) {
listAll(subFile, depth + 1);
}
}
}
}