Created
September 6, 2020 18:11
-
-
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
This file contains hidden or 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
/** | |
* 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