能麻烦你给个完整的例子吗? 我现在执行下面的代码: String[] command = new String[]{"md","C:\\test1"}; try { Runtime.getRuntime().exec(command); } catch (IOException e) { e.printStackTrace(); } 会抛出异常: java.io.IOException: Cannot run program "md": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at java.lang.Runtime.exec(Runtime.java:593) at java.lang.Runtime.exec(Runtime.java:466) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified 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) ... 3 more
能麻烦你给个完整的例子吗?(在Windows环境下) 我现在执行下面的代码: String[] command = new String[]{"md","C:\\test1"}; try { Runtime.getRuntime().exec(command); } catch (IOException e) { e.printStackTrace(); } 会抛出异常: java.io.IOException: Cannot run program "md": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at java.lang.Runtime.exec(Runtime.java:593) at java.lang.Runtime.exec(Runtime.java:466) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified 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) ... 3 more
能麻烦你给个完整的例子吗?(在Windows环境下) 我现在执行下面的代码: String[] command = new String[]{"md","C:\\test1"}; try { Runtime.getRuntime().exec(command); } catch (IOException e) { e.printStackTrace(); } 会抛出异常: java.io.IOException: Cannot run program "md": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at java.lang.Runtime.exec(Runtime.java:593) at java.lang.Runtime.exec(Runtime.java:466) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified 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) ... 3 more
public static void main(String[] args) { try { Process p = Runtime.getRuntime().exec("cmd.exe /c md C:\\test1"); while(p.getInputStream().read()!=-1); } catch (IOException e) { e.printStackTrace(); } }
能麻烦你给个完整的例子吗?
我现在执行下面的代码:
String[] command = new String[]{"md","C:\\test1"};
try {
Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
会抛出异常:
java.io.IOException: Cannot run program "md": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:466)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
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)
... 3 more
能麻烦你给个完整的例子吗?(在Windows环境下)
我现在执行下面的代码:
String[] command = new String[]{"md","C:\\test1"};
try {
Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
会抛出异常:
java.io.IOException: Cannot run program "md": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:466)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
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)
... 3 more
能麻烦你给个完整的例子吗?(在Windows环境下)
我现在执行下面的代码:
String[] command = new String[]{"md","C:\\test1"};
try {
Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
会抛出异常:
java.io.IOException: Cannot run program "md": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:466)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
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)
... 3 more
public static void main(String[] args) {
try {
Process p = Runtime.getRuntime().exec("cmd.exe /c md C:\\test1");
while(p.getInputStream().read()!=-1);
} catch (IOException e) {
e.printStackTrace();
}
}