public static void delFolder(String dirPath) {
try {
dAllFile(dirPath);
String fpath = dirPath;
File mPath = new File(fpath);
boolean tempFlag = mPath.delete();
} catch (Exception ex) {
Write.debug(""+ex.getMessage());
}
}
public static boolean dAllFile(String fPath) {
File myFile = new File(fPath);
if (!myFile.exists()) {
return false;
}
if (!myFile.isDirectory()) {
return false;
}
String[] tList = myFile.list();
File tempFile = null;
for (int i = 0; i < tList.length; i++) {
if (fPath.endsWith(File.separator)) {
tempFile = new File(fPath + tList[i]);
} else {
tempFile = new File(fPath + File.separator + tList[i]);
}
if (tempFile.isFile()) {
boolean tempFlag = tempFile.delete();
}
if (tempFile.isDirectory()) {
dAllFile(fPath + "/" + tList[i]);
delFolder(fPath + "/" + tList[i]);
return true;
}
}
return false;
}
删除指定文件或文件夹
最新推荐文章于 2022-03-26 00:14:40 发布