package com.recursion;
import java.io.File;
public class RecursionFile {
public static void main(String[] args) {
File file = new File("G:/A");
tree(file, 0);
}
private static void tree(File file, int level) {
StringBuffer stringBuffer = new StringBuffer("");
for (int i = 0; i< level; i++) {
stringBuffer.append("-");
}
File[] childs = file.listFiles();
for (int i = 0; i<childs.length; i++) {
System.out.println(stringBuffer+childs[i].getName());
if (childs[i].isDirectory()) {
tree(childs[i], level+1);
}
}
}
}
java 遍历目录
2022-06-02 12:02:45