JavaAPI中连接操作系统的类
一、Runtime类是一个典型的单例设计模式
private static Runtime currentRuntime = new Runtime();
/**
* Returns the runtime object associated with the current Java application.
* Most of the methods of class <code>Runtime</code> are instance
* methods and must be invoked with respect to the current runtime object.
*
* @return the <code>Runtime</code> object associated with the current
* Java application.
*/
public static Runtime getRuntime() {
return currentRuntime;
}
/** Don't let anyone else instantiate this class */
private Runtime() {}
- 所以我们在调用的时候只能 Runtime.getRuntime()
二、Runtime类的一个简单的应用
Runtime rt= Runtime.getRuntime();
Process p =rt.exec("notepad.exe");
- 这可以让你使用Java程序打开一个系统进程(上面代码打开的是记事本)
- exec()方法:public Process exec(String command) throws IOException
- 参数是command命令