编写一个Test类,获取Runtime实例,使用exec()方法执行一个dos命令,用于打开一个windows自带的记事本程序。
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Runtime.getRuntime().exec("cmd /E:ON /c start C:\\Users\\admin\\Desktop\\test.txt");
// E:ON 允许cmd扩展
// c 指之后为字符串
}
}