Skip to content

Instantly share code, notes, and snippets.

@GiriB
Last active October 7, 2025 15:42
Show Gist options
  • Select an option

  • Save GiriB/b79f47e4d970dec887a7 to your computer and use it in GitHub Desktop.

Select an option

Save GiriB/b79f47e4d970dec887a7 to your computer and use it in GitHub Desktop.
Open a URL in the default browser from Java
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public static void main(String args[]){
Desktop desktop = java.awt.Desktop.getDesktop();
try {
//specify the protocol along with the URL
URI oURL = new URI(
"https://www.google.com");
desktop.browse(oURL);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@afkvido
Copy link
Copy Markdown

afkvido commented May 23, 2022

Thanks for making this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment