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

前端 未结 4 597
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 13:33

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条回答
  • 2020-12-10 13:40

    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.

    0 讨论(0)
  • 2020-12-10 13:40

    You can try this:

    Runtime.getRuntime().exec("hh.exe index.chm");
    
    0 讨论(0)
  • 2020-12-10 13:41

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

    0 讨论(0)
  • 2020-12-10 13:42

    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.

    0 讨论(0)
提交回复
热议问题