Skip to content

Instantly share code, notes, and snippets.

@GiriB
Last active April 15, 2023 05:16
Show Gist options
  • Save GiriB/b79f47e4d970dec887a7 to your computer and use it in GitHub Desktop.
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

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