Minde
Minde

Reputation: 27

JAVA Open browser with a specified website

I have found that this code:

java.awt.Desktop.getDesktop().browse(URI);

will open up the users default browser and go to the specified URI. The problem that i am having is i cant figure out what the URI is. I want to open up google maps, http://maps.google.com/maps/search/, but the URI does not accept a string.

Does anyone know what the URI would be?

Upvotes: 0

Views: 2855

Answers (3)

Neeraj Jain
Neeraj Jain

Reputation: 7720

Try this way

URI openIt=new URL("http://maps.google.com/maps/search/").toURI();
java.awt.Desktop.getDesktop().browse(openIt);

Upvotes: 2

Daniel Stancu
Daniel Stancu

Reputation: 62

java.net.URI is a type in Java SE7.

URI myUri = URI.create(urlString);

Upvotes: 1

tonychow0929
tonychow0929

Reputation: 466

Construct the URI with a String directly will do:

URI uri = new URI("http://maps.google.com/maps/search/");
Desktop.getDesktop().browse(uri);

Another approach is to use the static method create()

URI uri = URI.create("http://maps.google.com/maps/search/");

Remember to handle exceptions.

Upvotes: 0

Related Questions