// clear the cache before time numDays private int clearCacheFolder(File dir, long numDays) { int deletedFiles = 0; if (dir!= null && dir.isDirectory()) { try { for (File child:dir.listFiles()) { if (child.isDirectory()) { deletedFiles += clearCacheFolder(child, numDays); } if (child.lastModified() < numDays) { if (child.delete()) { deletedFiles++; } } } } catch(Exception e) { e.printStackTrace(); } } return deletedFiles; }
activity中的代码:
webView.clearCache(true); clearCacheFolder(getApplicationContext().getCacheDir(), System.currentTimeMillis()); getApplicationContext().deleteDatabase("webview.db"); getApplicationContext().deleteDatabase("webviewCache.db"); clearCacheFolder(getApplicationContext().getCacheDir(), System.currentTimeMillis()); getApplicationContext().deleteDatabase("webview.db"); getApplicationContext().deleteDatabase("webviewCache.db");