How to Find Out Default File Opener with Java?

前端 未结 2 1319
一整个雨季
一整个雨季 2021-01-05 19:42

I need to find out default file opener for a given file on Windows so that I can customize the command arguments and open the file with the default opener/viewer.

My

2条回答
  •  無奈伤痛
    2021-01-05 20:27

    Use this approach to call default opener and enjoy!

    public void playItems2(...) throws Exception {
        ...
        Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler c:/mp3/myfile.mp3");
        p.waitFor();
        ...
    }
    

提交回复
热议问题