publi void delete(String path)throws Exception{
File file = new File(path);
Runtime rt = Runtime.getRuntime();
String cmd = "cmd.exe /c rd /s/q " + file.getAbsolutePath();
rt.exec(cmd);
}
本文提供了一个使用Java运行外部命令来删除文件的例子。通过Runtime类执行cmd命令,实现了跨平台的文件删除功能。
publi void delete(String path)throws Exception{
File file = new File(path);
Runtime rt = Runtime.getRuntime();
String cmd = "cmd.exe /c rd /s/q " + file.getAbsolutePath();
rt.exec(cmd);
}

被折叠的 条评论
为什么被折叠?