您的位置:首页 > 其它

Runtime类

2016-05-06 20:10 232 查看
Runtime类
Runtime类概述

每个 Java 应用程序都有一个Runtime 类实例,使应用程序能够与其运行的环境相连接。可以通过 getRuntime 方法获取当前运行时。

应用程序不能创建自己的 Runtime 类实例。

Runtime类使用

publicProcess exec(String command)

例子:

import java.io.IOException;

/*
* Runtime:每个 Java
应用程序都有一个 Runtime
类实例,使应用程序能够与其运行的环境相连接。
* exec(String command)
*/
public
class
RuntimeDemo {
public
static void
main(String[] args)
throws IOException {
Runtimer = Runtime.getRuntime();
// r.exec("winmine"); //打开扫雷游戏

r.exec("notepad");
//打开记事本
r.exec("calc"); //打开计算器
// r.exec("shutdown-s -t 10000");
r.exec("shutdown -a");
}
}

/*
* class Runtime { //该类使用了单例设计模式
* privateRuntime() {}
* privatestatic Runtime currentRuntime = new Runtime();
* publicstatic Runtime getRuntime() {
* return currentRuntime;
* }
* }
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: