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

来源:互联网 发布:excel相关系数矩阵 编辑:程序博客网 时间:2024/06/07 21:25
package cn.itcast_03;import java.io.IOException;/* * Runtime:每个Java应用程序都有一个Runtime类实例,使应用程序能够与其运行的环境相连接。 * 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");//10000秒后关机r.exec("shutdown -s -t 10000");//取消关机命令r.exec("shutdown -a");}}/* * class Runtime { * private Runtime() {} * private static Runtime currentRuntime = new Runtime(); * public static Runtime getRuntime() { *       return currentRuntime; *   } * } */




原创粉丝点击