Java 遍历文件夹所有文件的获取总大小
/**
* 获取文件夹下所有文件的大小或单个文件的大小
*
* @param file 文件对象
* @return
* @throws Exception
*/
public static long getFileSize(File file) throws Exception {
long size = 0;
if (file.isFile()) {
if (file.exists()) {
size = file.length();
}
} else {
final File[] children = file.listFiles();
if (children != null && children.length > 0) {
for (final File child : children) {
size += getFileSize(child);
}
}
}
return size;
}