Sunday, 24 April 2016

How to open a website or local site in browser using Java code ?


Opening a website or local site using Java code

Example
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

try {
   java.net.URI uri = new java.net.URI("http://www.google.com");
   // Open browser with website URL
   desktop.browse(uri);

   File localFile = new File("C:\\shaan\\localsite\\home.html");
   // Open browser with local HTML page
   desktop.open(localFile);
} catch (URISyntaxException e) {
   e.printStackTrace();
} catch (IOException e) {
   e.printStackTrace();

}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.