How to Open HTML file using Java?

Viewed 66559

I try to open HTML file from local (In my system) by Java program. I tried some of the program got through stack overflow but its not working as much.

For E.G.: I have this small HTML file.

<html>
  <head> 
    Test Application
  </head>
  <body>
     This is test application
  </body>
</html>

My Java code:

Runtime rTime = Runtime.getRuntime();
String url = "D:/hi.html";
String browser = "C:/Program Files/Internet Explorer/iexplore.exe ";
Process pc = rTime.exec(browser + url);
pc.waitFor();

Any solution or tips appreciated.

3 Answers
URI oURL = new URI(url);
Desktop.getDesktop().browse(oURL);

Apart from that, make sure that file is already opened in your desired browser. Check the icon on the file, If it is showing like a text file, you might have already opened with Text file. So change the default program to the desired program.

Related