Java method of includes this folder to delete all contents under the specified folder
- 2020-05-19 04:46:27
- OfStack
As follows:
// Delete folder
private static void deleteDirectory(File file) {
if (file.isFile()) {// Indicates that the file is not a folder
file.delete();
} else {
// You get the current path first
String[] childFilePaths = file.list();
for (String childFilePath : childFilePaths) {
File childFile = new File(file.getAbsolutePath() + "/" + childFilePath);
deleteDirectory(childFile);
}
file.delete();
}
}
public static void main(String[] args) {
File del_file = new File("D:/Test/ibs" + "/temp/");
deleteDirectory(del_file);
}