Using the Desktop class to launch a URL with default browser : Desktop « JDK 6 « Java






Using the Desktop class to launch a URL with default browser

  

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class UsingDesltopClassToLaunch {
  public static void main(String[] a) {
    try {
      URI uri = new URI("http://www.java2s.com");
      Desktop desktop = null;
      if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
      }

      if (desktop != null)
        desktop.browse(uri);
    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (URISyntaxException use) {
      use.printStackTrace();
    }

  }
}

          
  








Related examples in the same category

1.Invoke the default editor to edit a file
2.Using the system default setting to open a file
3.Open a office word file with Java
4.Using system default printer to print a file out
5.Send out email
6.Open Mail client
7.Desktop Help Applications
8.This program demonstrates the desktop app API.