Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the user's default browser in Java

Tags:

java

browser

I want to know how to get the location of the user's default Internet browser in Java. How can I get this? I would prefer it as a URI to the browser's executable file. Must work cross-platform.

like image 556
Ky. Avatar asked Jul 25 '26 11:07

Ky.


2 Answers

The safest thing you can do is something like this:

if (Desktop.isDesktopSupported()) 
{
  Desktop.getDesktop().browse("your url here");
}

more info on the Desktop class (mail, print, edit, etc) here

like image 199
Pablo Fernandez Avatar answered Jul 28 '26 16:07

Pablo Fernandez


You should be using the Desktop class for this. This is the cross platform API that will invoke the default browser.

like image 32
camickr Avatar answered Jul 28 '26 14:07

camickr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!