I need to calculate the physical size of a directory. The naive algorithm to do that could be :
public static long getFolderSize(File dir) {
long size = 0;
for (File file : dir.listFiles()) {
if (file.isFile()) {
System.out.println(file.getName() + " " + file.length());
size += file.length();
}
else
size += getFolderSize(file);
}
return size;
}
but how to deal with symbolic links ?
Sometimes 4096 bytes is the smallest allocation unit for some filesystems. That's why directory has 4096. The same thing apply to files. Even though some files might report fewer than 4096, they are actually taking al least 4096 of storage from disk.
When listing the contents of a directory using the ls command, you may have noticed that the size of the directories is almost always 4096 bytes (4 KB). That's the size of space on the disk that is used to store the meta-information for the directory, not what it contains.
Go to Windows Explorer and right-click on the file, folder or drive that you're investigating. From the menu that appears, go to Properties. This will show you the total file/drive size. A folder will show you the size in writing, a drive will show you a pie chart to make it easier to see.
Average Android and iOS file size Of all mobile apps published on the app stores, the average Android app file size is 11.5MB. And the average iOS app file size is 34.3MB.
getCanonicalPath() This typically involves removing redundant names such as "." and ".." from the pathname, resolving symbolic links (on UNIX platforms). http://docs.oracle.com/javase/1.4.2/docs/api/java/io/File.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With