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
Cannot do with pure Java alone.
In case of Windows, you need to read registry. Suppose you need to find out file association for .mp3
HKEY_CLASSES_ROOT\.mp3
. Usually its
"mp3file
".HKEY_CLASSES_ROOT\mp3file\shell\open\command
.
The value in there is a string
pointing to an executable to open
.mp3 files with.Now this cant be done in Java, you need to choose appropriate 3rd party lib to do this for you.
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();
...
}