Java是一门强大的语言 和其他语言一样可以用递归函数来删除一个包含文件和子目录的目录首先需要import相关的单元
import javaioFile;
以下是递归函数内容:
private Boolean pDeleteDirectory(String filePath) {
Boolean bTotalRlt = true;
File file = new File(filePath);
File[] fileList = filelistFiles();
String dirPath = null;
if (fileList != null) {
for (int i = ; i < fileListlength; i++) {
if (fileList[i]isFile()) {
bTotalRlt = bTotalRlt && fileList[i]delete();
}
if (fileList[i]isDirectory()) {
dirPath = fileList[i]getPath();
bTotalRlt = bTotalRlt && pDeleteDirectory(dirPath);
}
}
bTotalRlt = bTotalRlt && filedelete();
}
return bTotalRlt;
}