RunTime类,让程序自动打开,关闭程序


public class T1 {
public static void main(String[] args) {

Runtime runtime = Runtime.getRuntime();
Process process=null;

try {
process= runtime.exec("notepad.exe");//执行记事本程序,返回一个进程对象
} catch (IOException e) {
e.printStackTrace();
}
try {
Thread.sleep(3000);//3秒后关闭记事本
} catch (InterruptedException e) {
e.printStackTrace();
}
process.destroy();//关闭记事本
}
}

你可能感兴趣的:(runtime,java)