void cleanDirectory() { File tarDir = this.getCacheDir();//起始目錄 if(!tarDir.exists()) { return; } String fList[] = tarDir.list(); if(fList == null) { tarDir.delete();//刪除目錄 return; } for(int i = 0; i < fList.length; i++) { File file = new File(tarDir, fList[i]); if(file.isDirectory()) { cleanSubDirectory(tarDir, fList[i]); } else { file.delete(); } } } void cleanSubDirectory(File sDir, String dirName) { File tarDir = new File(sDir, dirName); if(!tarDir.exists()) { return; } String fList[] = tarDir.list(); for(int i = 0; i < fList.length; i++) { File file = new File(tarDir, fList[i]); if(file.isDirectory()) { cleanSubDirectory(tarDir, fList[i]); } else { file.delete(); } } tarDir.delete(); }
清除目錄下檔案
週一, 2012-09-17 16:07
#1
清除目錄下檔案