package test;
import java.io.File;
public class FileTest {
static int n=0;
public static void main(String[] args) {
File f = new File("C:/bea/");
listFiles(f);
System.out.println("共有文件数:"+n);
}
public static void listFiles(File f) {
if (f.isDirectory()) {
System.out.println("d>>" + f.getAbsolutePath());
File[] files = f.listFiles();
for (File file : files) {
listFiles(file);
}
} else {
n++;
System.out.println("f>>" + f.getAbsolutePath());
}
}
}
递归统计文件数
最新推荐文章于 2022-09-09 23:28:00 发布