I am writing a program in java which would execute winrar and unzip a jar file for me placed in h:\myjar.jar
into the folder h:\new
. My java code goes something like this
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();
}
}
}
When I execute this, I am getting this error
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
Can anyone tell me why am I encountering such a problem. What is the change I need to incorporate in code so that it works?