Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android directory size

Tags:

file

android

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 ?

like image 326
user954469 Avatar asked Nov 22 '11 10:11

user954469


People also ask

Why are all directories 4096 bytes?

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.

How much space does a directory take?

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.

How can I see folder size?

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.

What is the file size of Android?

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.


1 Answers

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

like image 110
lingceng Avatar answered Oct 06 '22 22:10

lingceng