How to get the exact size of cache directory : android

前端 未结 3 1584
别跟我提以往
别跟我提以往 2020-12-14 22:14

NEED: I simply trying to get occupied cache size of each application which is installed in my phone.

MY APPROACH:

PackageManager packageManager = get         


        
3条回答
  •  情深已故
    2020-12-14 22:51

    Calling length on a directory doesn't always return the correct size. You could try to iterate over the file list and add up all file sizes to get the total directory size.

    Like this:

    long size = 0;
    File[] files = cacheDirectory.listFiles();
    for (File f:files) {
        size = size+f.length();
    }
    

提交回复
热议问题