public static long sizeOfDirectory(final File directory) {
checkDirectory(directory);
return sizeOfDirectory0(directory);
}
private static long sizeOfDirectory0(final File directory) {
final File[] files = directory.listFiles();
if (files == null) { // null if security restricted
return 0L;
}
long size = 0;
for (final File file : files) {
if (!isSymlink(file)) {
size += sizeOf0(file); // internal method
if (size < 0) {
break;
}
}
}
return size;
}
private static long sizeOf0(final File file) {
if (file.isDirectory()) {
return sizeOfDirectory0(file);
}
return file.length(); // will be 0 if file does not exist
}
linux du 命令里做了哪些优化?
Q: 有木有引入线程池或者其它优化之类的?