- package cn.javastudy.p7.runtime.demo;
- import java.io.IOException;
- import java.util.Properties;
- public class MyRunTime {
- public static void main(String[] args) throws IOException
- {
- Runtime runTrim=Runtime.getRuntime();
- int a=runTrim.availableProcessors();
- Properties p=System.getProperties();
- p.setProperty("sun.boot.class.path", "D:\\Program Files\\Tencent\\QQ\\Bin\\");
- System.out.println(a);
- runTrim.exec("QQ.exe");
- }
- }
- /*
- * 4
- Exception in thread "main" java.io.IOException: Cannot run program "QQ.exe": CreateProcess error=2, ?????????
- at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
- at java.lang.Runtime.exec(Runtime.java:593)
- at java.lang.Runtime.exec(Runtime.java:431)
- at java.lang.Runtime.exec(Runtime.java:328)
- at cn.javastudy.p7.runtime.demo.MyRunTime.main(MyRunTime.java:14)
- Caused by: java.io.IOException: CreateProcess error=2, ?????????
- at java.lang.ProcessImpl.create(Native Method)
- at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
- at java.lang.ProcessImpl.start(ProcessImpl.java:30)
- at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
- ... 4 more
- */
- //为什么运行出错呢
复制代码 |
|