Runtime 的用法
1.该类主要代表了应用程序的运行环境。一个RunTime就代表一个运行环境。
2.RunTime类常用的方法:
(1) getRuntime():该方法用于返回当前应用程序的运行环境对象。
(2) exec(String command):该方法用于根据指定的路径执行对应的可执行文件。
代码的实现方式
import java.io.*;
public class Example10_3 {
public static void main(String args[]) {
try{
Runtime ce=Runtime.getRuntime();//配置运行环境;
ce.exec("C:\Program Files\Internet Explorer\iexplore.exe "); 调出该文件运行程序
// File file=new File(“c:/windows”,“Notepad.exe”);
// ce.exec(file.getAbsolutePath());
// ce.exec(file.getAbsolutePath());
// file=new File(“C:\Program Files\Internet Explorer”,"IEXPLORE www.baidu.com ");
// ce.exec(file.getAbsolutePath());
}
catch(Exception e) {
System.out.println(e);
}
}
}