System和Runtime

来源:互联网 发布:游族网络 加班 编辑:程序博客网 时间:2024/05/29 15:15

System中定义了一些与与系统相关的属性和方法,这些方法都是静态的,所以引用这些属性和方法,直接使用System类调用即可。

Runtime表示虚拟机的属性和方法。Runtime是采用单例模式设计,用getRuntime()获得实例对象。

Runtime中提供了exec()方法,用于执行dos命令,效果和在命令行窗口中输入dos命令的效果一样。在exec()中的命令语句要放在“”中。例如:exec("notepad.exe").

package study;
import java.io.*;
public class Example13 {
public static void main(String[] args) throws IOException{
Runtime rt=Runtime.getRuntime();
rt.exec("notepad.exe");
}
}

结果:



原创粉丝点击