import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class Test {
public Test() {
try {
// 运行普通dos命令
Runtime.getRuntime().exec("cmd.exe /c regedit");
// 用默认的关联程序打开文件
// Runtime.getRuntime().exec("cmd.exe /c C:\\face1.jpg");
// 用指定的程序打开文件,记事本打开文本文件
// Runtime.getRuntime().exec("cmd.exe /c notepad C:\\hello.txt");
// 在Swing编程中还可以使用DeskTop打开关联文件
// Desktop d = Desktop.getDesktop();
// d.open(new File("C:\\face1.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new Test();
}
}
spawn调用exe传递参数的方法,和你用window的cmd,运行exe方法一样。没有区别。spawn实际上就是实现的window的命令行的功能。