Runtime 的用法

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);
}
}
}

](https://img-blog.csdnimg.cn/20190307125741114.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80Mzg4NTU2Ng==,size_16,color_FFFFFF,t_70)

猜你喜欢

转载自blog.csdn.net/weixin_43885566/article/details/88297332