Do you know how can I get the folder size in Java?
The length() method in the File class only works for files, using that method I always get a size of 0.
Go through a folder, file by file, getting the size of each file and adding them to the variable size.
static int size=0;
public static int folderSize(File folder){
size = 0;
File[] fileList = folder.listFiles();
for(File file : fileList){
if(!file.isFile()){
folderSize(file);
}
size += file.length();
}
return size;
}