Open URL in Java using Default Browser

An example of browsing a web URL in java using the default web browser.


import java.awt.Desktop;
class BrowseURL
public static void main(String args[]) throws Exception

// Create Desktop object
Desktop d=Desktop.getDesktop();

// Browse a URL, say
d.browse(new URI(""));


Try it yourself! It works! The default handler for http:// protocol will be given the address to open.

Posted by at on

Tags: Abstract Window Toolkit,