Reputation: 85
This is my code. I am able to open browser but it will not load the html source.
class Browser {
public static void main(String[]args) {
try {
Runtime rtime = Runtime.getRuntime();
String url = "C:/Program Files (x86)/Internet Explorer/DD.html";
String brow = "C:/Program Files (x86)/Internet Explorer/iexplore.exe";
Process pc = rtime.exec(brow + url);
pc.waitFor();
} catch (Exception e) {
System.out.println("\n\n" + e.getMessage());
}
}
}
Upvotes: 2
Views: 7153
Reputation: 14600
You have too many spaces in the brow
value - I presume that's just a formatting issue in the question.
Using the single-argument version of exec
splits the input string by spaces, so your code will try to execute a command C:/Program
and pass it arguments "Files"
, "(x86)/Internet"
, "Explorer/iexplore.exeC:/Program"
, "Files"
, etc.
Note that "Explorer/iexplore.exeC:/Program"
- because you concatenated the two strings without a space.
You could resolve these issues by passing an array of strings to exec()
instead of using the single-string version, but you're better off using Desktop.getDesktop().browse(URI);
Upvotes: 0