Java Tips: How to launch default browser from Java applicationsBy Angsuman Chakraborty, Gaea News Network
Monday, February 8, 2010
Using the java.awt.Desktop class you can easily launch the default browser (of your operating system) from Java applications. Read below for more details and the code.
java.net.URI uri = new URI(”http://gaeatimes.com“);
The documentation for browse() states:
Launches the default browser to display a URI. If the default browser is not able to handle the specified URI, the application registered for handling URIs of the specified type is invoked. The application is determined from the protocol and path of the URI, as defined by the URI class.
If the calling thread does not have the necessary permissions, and this is invoked from within an applet, AppletContext.showDocument() is used. Similarly, if the calling does not have the necessary permissions, and this is invoked from within a Java Web Started application, BasicService.showDocument() is used.
Did you like this tip? Consider subscribing to our site for more such tips.