[Java] 纯文本查看 复制代码
import java.io.File;
public class Demo {
static int i = 0;
public static void main(String[] args) {
File dirs = new File("d:\\");
File[] listFiles = dirs.listFiles();
for (File file : listFiles) {
if (file.isDirectory()) {
count(file);
System.out.println(file.getName() +"文件夹-----有"+ i+"个.txt文件");
i = 0;
}
}
}
private static void count(File file) {
File[] sonFiles = file.listFiles();
for (File file2: sonFiles) {
if (file2.isDirectory()) {
count(file2);
} else if (file2.getName().endsWith(".txt")) {
i++;
}
}
}
}