Last active
April 15, 2023 05:16
-
-
Save GiriB/b79f47e4d970dec887a7 to your computer and use it in GitHub Desktop.
Open a URL in the default browser from Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for making this!