例如要打开一个文件的内容:


java基础—Runtime类使用_Java教程


import java.io.IOException;
import java.util.Properties;
import java.util.Set;
public class StstemDemos {

	public static void main(String[] args) throws Exception 
	{
		//method1();
		method2();

	}
   private static void method2() throws  Exception {
		// TODO Auto-generated method stub
		Runtime r = Runtime.getRuntime();
		Process  p = r.exec("notepad.exe  C:\\Users\\Administrator\\Desktop\\exam\\src\\com\\itheima\\Test3.java");
		Thread.sleep(50000);
		p.destroy();
	}
}

运行程序后:

java基础—Runtime类使用_Java开发_02