寫android應用的時候需要刪除文件中的內容。但是總是刪除不掉。百度了好久。。尼瑪啊。。沒java基礎會讓你很蛋疼的。。
public boolean delFile(String strPath) {
boolean filebool = false;
File file = new File(strPath);
if (file.exists() && file.isDirectory()) {
if (file.listFiles().length == 0) {
file.delete();
} else {
File[] ff = file.listFiles();
for (int i = 0; i < ff.length; i++) {
if (ff[i].isDirectory()) {
delFile(strPath);
}
ff[i].delete();
}
}
}
// file.delete();// 如果要把文件夾也刪除。。就去掉註釋。。
filebool=true;
return filebool;
}