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");
}
}

结果:

System和Runtime


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-12-12
  • 2021-10-04
  • 2021-11-08
  • 2022-01-11
  • 2021-10-08
猜你喜欢
  • 2021-11-07
  • 2022-12-23
  • 2021-09-28
  • 2021-07-29
  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
相关资源
相似解决方案