Runtime:每个 Java 应用程序都有一个 Runtime 类实例,使应用程序能够与其运行的环境相连接。
其中一个方法:
exec(String command) 在单独的进程中执行指定的字符串命令,就是可以直接打开软件,里面填写软件名称
public class RuntimeDemo {
public static void main(String[] args) throws IOException {
Runtime r = Runtime.getRuntime();
//r.exec("winmine"); 打开扫雷软件
//r.exec("notepad"); 打开记事本软件
//r.exec("calc");//打开计算器
// r.exec("shutdown -s -t 10000");//定时关机。10000毫秒后关机
//r.exec("shutdown -a"); //取消关机命令
}
} /*
* Runtime的部分源码:使用了单例模式的饿汉式
*
* class Runtime {
* private Runtime() {}
* private static Runtime currentRuntime = new Runtime();
* public static Runtime getRuntime() {
* return currentRuntime;
* }
* }
*/