wtf1989 wtf1989 - 1 year ago 62
Java Question

Java file path and url in Process class

How to edit these code to make it work:

String[] var1 = { "\"C:\\Program Files\\Internet Explorer\\iexplore.exe" };
String[] var2 = { "" };

Runtime runTime = Runtime.getRuntime();
Process process = runTime.exec("\"C:\\Program Files\\Internet Explorer\\iexplore.exe\"");
Process process2 = runTime.exec(var1,var2);

first "process" work fine, but "process2" open default site in IE instead of

Answer Source

the var1 is wrong you have a scaped " at the begin

it must be:

String[] var1 = { "C:\\Program Files\\Internet Explorer\\iexplore.exe" };

that is the reason of the exception

Now according to the doc:

enter image description here

you need to pass in the same array the command to execute and the parameters...

so it must be only

Process process2 = runTime.exec(var1);


String[] var1 = { "C:\\Program Files\\Internet Explorer\\iexplore.exe", "" };