0

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?

3 Answers 3

2

Try this way

URI openIt=new URL("http://maps.google.com/maps/search/").toURI();
java.awt.Desktop.getDesktop().browse(openIt);
Sign up to request clarification or add additional context in comments.

Comments

1

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

URI myUri = URI.create(urlString);

1 Comment

Thank you for replying so fast. This code works. Try catch is also needed for it to work in my case.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.