/**
* Deletes a directory or file.
*
* @param file
* directory or file to delete
*
* @throws NoSuchFileException
* if the file does not exist <i>(optional specific exception)</i>
* @throws DirectoryNotEmptyException
* if the file is a directory and could not otherwise be deleted
* because the directory is not empty <i>(optional specific
* exception)</i>
* @throws IOException
* if an I/O error occurs
*/
public static void deleteFile(File file) throws IOException {
if (file == null || !file.exists()) {
return;
}
if (file.isDirectory()) {
// Delete all files in folder, include sub-folders
File[] files = file.listFiles();
for (File singleFile : files) {
if (singleFile.isFile()) {
// file
cleanUp(singleFile);
} else {
// folder
deleteFile(singleFile);
}
}
}
cleanUp(file);
}
public static void cleanUp(Path path) throws IOException{
Files.delete(path);
}
public static void cleanUp(File file) throws IOException{
cleanUp(file.toPath());
}