Recursivly delete directory in Java
Description
The following code shows how to recursivly delete directory.
Example
// w w w .j a v a 2 s. c o m
import java.io.File;
public class Main {
public static boolean delete(File directory) {
boolean result = false;
if (directory.isDirectory()) {
File[] files = directory.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
delete(files[i]);
}
files[i].delete();
}
result = directory.delete();
}
return result;
}
}