Use the Desktop class to launch a URL with default browser in Java
Description
The following code shows how to use the Desktop class to launch a URL with default browser.
Example
/*from w w w . j a v a 2 s. c o m*/
import java.awt.Desktop;
import java.net.URI;
public class Main {
public static void main(String[] a) throws Exception{
URI uri = new URI("http://www.java2s.com");
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
if (desktop != null)
desktop.browse(uri);
}
}