Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { private static String SAVE_PATH = ""; public static boolean cleanCache() { File root = new File(SAVE_PATH); deleteCacheFile(root); long size = getDirSize(root); return size == 0; } private static void deleteCacheFile(File file) { if (file.isFile()) { file.delete(); } else { File[] files = file.listFiles(); for (File f : files) { deleteCacheFile(f); } } } private static long getDirSize(File file) { long total = 0; if (file.exists()) { if (file.isFile()) { return file.length(); } else if (file.isDirectory()) { for (File f : file.listFiles()) { total += getDirSize(f); } } } return total; } }