Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; public class Main { private static ArrayList<File> filesInCache = new ArrayList<>(); /** * in KB * * @return KB */ public static long getCacheSize() { long sum = 0; if (filesInCache == null) { return 0; } else { for (File file : filesInCache) { if (!file.exists()) continue; if (file.isFile()) { sum += file.length(); //LogUtils.i(TAG, file.getAbsolutePath() + "isFile"); } else if (file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { if (!files[i].exists()) continue; if (files[i].isFile()) { //LogUtils.i(TAG, file.getAbsolutePath() + "isDir"); sum += file.length(); } } } } } return sum / 1024; } }