不多说,直接上代码
public class Test {
public static void deleteFile(File file) {
if (file.exists()) {
if (file.isFile()) {
file.delete();
}
else if (file.isDirectory()) {
deleteDirectory(file);
}
}
}
private static void deleteDirectory(File file) {
File files[] = file.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
files[i].delete();
}
else if (files[i].isDirectory()) {
deleteDirectory(files[i]);
}
}
file.delete();
}
/** <一句话功能简述>
* @param args
*/
public static void main(String[] args) {
deleteFile(new File("d:\\//tmp/"));
}
}