Java常用类Runtime类和Process类
发布时间:2010/7/16 10:31:47 来源:城市学习网 编辑:ziteng
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查看其中的方法。