日期:2014-05-18 浏览次数:20774 次
import java.io.File; public class Test{ //递归删除 public static void deleteDir(File dir){ if(dir.isDirectory()){ File[] files = dir.listFiles(); for(int i=0; i<files.length; i++) { deleteDir(files[i]); } } dir.delete(); } public static void main(String args[]) { deleteDir(new File("c:\\temp\\2")); } }
------解决方案--------------------
import java.io.*;
public class Exccmd {
//Construct the application
public Exccmd() {
}
//Main method
public static void main(String[] args) {
String cmd = "del /s"+你的目录;
try {
Runtime.getRuntime().exec(cmd);
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}