Java常用类Runtime类和Process类

Runtime类封装了运行时的一些方法。Runtime的构造方法声明为私有(private)的,所以我们就不可能条用。

只有通过使用Runtime rt=Runtime.getRuntime();获取Runtime对象的引用。

Java代码

public class RuntimeDemo {

public static void main(String []args) {

Runtime rt= Runtime.getRuntime();

Process p=null;

try

{

p.exec("notepad.exe"); //运行记事本程序

Thread.sleep(1000);//运行1分钟

} <SPAN style="COLOR: #0000ff">catch</SPAN> (Exception e) {

System.out.println(<SPAN style="COLOR: #800000">"Error executing notepad."</SPAN>);

}

Thread.destroy();

}

}

Runtime类是JVM的进程信息,需要时可以通过API查看其中的方法。

标签: 常用RuntimeProcess
------分隔线----------------------------
· 首页 · 注册

百鸣[Baiming.org]欢迎您 百鸣[Baiming.org]欢迎您~