12

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?

4 Answers 4

19

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Just remember the edge case when using this. For example a web developer probably has some sort of editor/ide set as their default app to open html files. Might need to dig a little deeper if developers are part of your main users.
Dektop.open(File)/Desktop.edit(File) & Desktop.browse(URI) might open in Dreamweaver & FF respectively. It would be better to use Desktop.browse(URI) in this case.
6

If you're not using Java 6 (or not sure your users will) - you can use Bare Bones Browser Launcher to launch the default browser. It uses Java 6 Desktop.open() if available, and falls back to platform specific approaches if it's not.

Comments

2

Check this page, this can give you a much more detailed usage of the Desktop API.

Comments

0

You can try this:

Runtime.getRuntime().exec("hh.exe index.chm");

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.