设计模式_单例模式的Java代码体现Runtime类

来源:互联网 发布:中国统计年鉴数据下载 编辑:程序博客网 时间:2024/06/01 07:35
package cn.itcast_03;import java.io.IOException;/* * Runtime:每个 Java 应用程序都有一个 Runtime 类实例,使应用程序能够与其运行的环境相连接。 * public Process exec(String command):在单独的进程中执行指定的字符串命令(直接执行使用dos命令)。 */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");//关闭你的计算机r.exec("shutdown -a");// 中止要关闭的计算机}}/* * class Runtime {  * private static Runtime currentRuntime = new Runtime(); *  public static Runtime getRuntime() {  *  return currentRuntime;  *  } *  private Runtime() { * }  * } */

0 0