Runtime类封装了运行时的一些方法。Runtime的构造方法声明为私有(private)的,所以我们就不可能条用。
只有通过使用Runtime rt=Runtime.getRuntime();获取Runtime对象的引用。
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分钟
} catch (Exception e) {
System.out.println("Error executing notepad.");
}
Thread.destroy();
}
}
Runtime类是JVM的进程信息,需要时可以通过API查看其中的方法。