I am trying to invoke an HTML File stored on my desktop from inside a JAVA code as below.
I found this code snippet here
try
{
Runtime r= Runtime.getRuntime();
String url = "C:\\Users\\Rana\\Desktop\\test.html";
String browser ="C:/Program Files/Mozilla Firefox/firefox.exe ";
Process p = r.exec(browser);
p.waitFor();
}
catch(Exception e)
{
e.printStackTrace();
}
I tried using backslash and forward slashes, both. But it is throwing this error in both case....
java.io.IOException: Cannot run program "C:/Program": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at package1.Test.main(Test.java:22)
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:376)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
The path "browser" is present.
Please suggest where I am doing wrong.
Cannot run program C:/Program-- which isn't what you are trying to run. I think the space in the path is making it not work.