java调用cmd命令 删除文件
也可以执行其他cmd命令
下面是一个简单演示代码
- package com.lobo.server;
- import java.io.IOException;
- public class Cmd {
- public static void main(String[] args){
- String filepath="d://test.txt";
- Runtime rt = Runtime.getRuntime();
- try{
- rt.exec("cmd /c del "+filepath);
- } catch (IOException e){
- e.printStackTrace();
- }
- }
- }
这篇博客展示了如何使用Java通过调用CMD命令来删除指定的文件。提供了一个简单的代码示例,演示了如何利用Runtime类的exec方法执行"cmd /c del"命令来删除D盘下的test.txt文件。
1万+

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



