当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
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查看其中的方法。
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved