Opening an external html file through Java

Q. How do i invoke an external application(web browser) to display an html page?

A. Perseverance and Patience are those which helped me to reach the solution to this problem. I spent more than 4 hours to find a solution, encountering many tips in the web, only to find at the end that all it takes is to pay attention to  subtle facts like “spaces” and “slashes”.

Here is how you get things to work.
First,  create an html file and name it as “sample.html“. Place it anywhere you  wish.
Next, you need to code the following:

Here, as you would have observed, browser contains the path to Internet Explorer browser and url contains the path to sample.html.

What you would not have observed is the “space” i have left in the browser path, at the end, after iexplore.exe.

This is what that matters and not placing this space is what makes many programmers break their heads making them think that runtime.exec doesn’t work. Also note the slash in the file path and browser path. I have used  forward slash at all instances. This would be obvious to you from the error message you get when you try to replace any of them  with backward slash.

Thats it!

Just run the code and enjoy!

Pass this tip to your colleagues!