import java.io.File;
public class DiskUsage {
public static long diskUsage(File root) {
long total = root.length();
if (root.isDirectory()) {
for (String childName : root.list()) {
File child = new File(root, childName);
total += diskUsage(child);
}
}
if (root.equals(new File("D:\\Program Files\\Git")))
System.out.println(total + "\t" + root);
return total;
}
public static void main(String[] args) {
diskUsage(new File("D:\\Program Files\\Git"));
}
}
用java计算一个文件目录的大小
最新推荐文章于 2023-07-24 19:27:06 发布