我正在编写一个Java程序,它可以执行Winrar并将放在
当我执行这个命令时,出现了这个错误。
h:\myjar.jar
中的JAR文件解压到h:\new
文件夹中。我的Java代码如下:import java.io.File;
import java.io.IOException;
public class MainClass {
public static void main(String[] args) {
Runtime r = Runtime.getRuntime();
Process p = null;
try {
File dir = new File("C:/Program Files/WinRAR");
p = r.exec("winrar x h:\\myjar.jar *.* h:\\new", null, dir);
} catch (IOException e) {
e.printStackTrace();
}
}
}
当我执行这个命令时,出现了这个错误。
java.io.IOException: Cannot run program "winrar" (in directory "C:\Program Files\WinRAR"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at MainClass.main(MainClass.java:16)
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>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 4 more
有人能告诉我为什么会遇到这样的问题吗?我需要在代码中做出哪些更改才能使其正常工作?