Cross-platform way to open a file using Java 1.5

后端 未结 8 808

I\'m using Java 1.5 and I\'d like to launch the associated application to open the file. I know that Java 1.6 introduced the Desktop API, but I need a solution for J

8条回答
  •  青春惊慌失措
    2020-12-16 18:27

    Another answer (by boutta) suggests using SWT. I wouldn't recommend referencing the library for this purpose only, but if you are using it already, simply execute:

    Program.launch("http://google.com/");
    

    Take note that this method will only work (and return true) if a Display object has already been created (for instance by creating a Shell). Also take note that it must run in the main thread; e.g.:

    Display.syncExec(new Runnable() {
        public void run() {
            Program.launch("http://google.com/");
        }
    });
    

    In the example above I've launched a URL, but launching files works in the same way.

提交回复
热议问题