Search code examples
javapythonequivalentpython-webbrowser

Java equivalent to Python's webbrowser.open()


I just finished a project with Python and now I am trying to convert it into Java. I have a lot of things done but I am stuck on this one part. In python, I am opening a random link from a list on the web browser with this code

import webbrowser

urls = [# list of URLs]
url_to_open = random.choice(urls)
webbrowser.open(url_to_open)

In Java I was able to replicate the choosing of the random URL, but I am not sure how to open the URL in the web browser.

So, what is the Java equivalent to Python webbrowser.open()?


Solution

  • java.awt.Desktop.browse(URI) has this facility.