How can I open an HTML file in the default browser from a Java Swing application?

browser, java, swing

Solution

If you are using Java 6, use Desktop.open(). It allows you to open any file with the default application associated with its file type on the system.

Problem

My Java Swing application generates an HTML file, and I want to open it with the default browser when it is generated and saved. How can I do this?

Original source