Skip to content

Instantly share code, notes, and snippets.

@antic-ml
Created September 6, 2020 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antic-ml/a5c099defb5d15032c5531920eae75b1 to your computer and use it in GitHub Desktop.
Save antic-ml/a5c099defb5d15032c5531920eae75b1 to your computer and use it in GitHub Desktop.
Open the system's native web browser from Java and display a URL
/**
* Open the system's native web browser to display a URL.
*/
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class BrowserOpen {
public static void main(String[] args) {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URI("http://www.google.com"));
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment