天天看點

Bqq伺服器的緩存檔案放什麼目錄,如何清除Android應用程式緩存?

poate ITI合并ASTA

static int clearCacheFolder(final File dir, final int numDays) {

int deletedFiles = 0;

if (dir!= null && dir.isDirectory()) {

try {

for (File child:dir.listFiles()) {

//first delete subdirectories recursively

if (child.isDirectory()) {

deletedFiles += clearCacheFolder(child, numDays);

}

//then delete the files and subdirectories in this dir

//only empty directories can be deleted, so subdirs have been done first

if (child.lastModified() < new Date().getTime() - numDays * DateUtils.DAY_IN_MILLIS) {

if (child.delete()) {

deletedFiles++;

}

}

}

}

catch(Exception e) {

Log.e("ATTENTION!", String.format("Failed to clean the cache, error %s", e.getMessage()));

}

}

return deletedFiles;

}

public static void clearCache(final Context context, final int numDays) {

Log.i("ADVL", String.format("Starting cache prune, deleting files older than %d days", numDays));

int numDeletedFiles = clearCacheFolder(context.getCacheDir(), numDays);

Log.i("ADVL", String.format("Cache pruning completed, %d files deleted", numDeletedFiles));

}