tags:

views:

275

answers:

2

How do I open a file with the default associated program in Java? (for example a movie file)

+3  A: 

You can use Desktop.getDesktop().open(File file). See the following question for other options: "[Java] How to open user system preffered editor for given file?"

Zach Scrivena
I keep getting this exception when trying with a movie file but it work with an image file (bmp): java.io.IOException: Failed to open file:/D:/vidz/2006-04-02.wmv. Error message: The parameter is incorrect.
Frederic Morin
Can you provide your code in the question? Also, which OS and Java version are you using?
Zach Scrivena
what I don't understand is that it work with images... anyway I'm using Java 1.6.0.06 and here's the code: File file = new File(MoviePlay.getInstance().getBasePath(), movieFile.getPath());try { Desktop.getDesktop().open(file); } catch(ex) { ... }
Frederic Morin
oh and btw, file.exist() == true
Frederic Morin
@Blade: Could you try file.getCanonicalFile() to see if there's a difference?
Zach Scrivena
I get this message instead: java.io.IOException: Failed to open file:/D:/vidz/2006-04-02.wmv. Error message: The parameter is incorrect.
Frederic Morin
I know it's been a long time but... the problem was my machine. The default program assiciation in my Windows XP are not ok and I'm having issue in other programs. I tried with other machines since then and this method work just fine ! Accepted !
Frederic Morin
A: 

SwingHacks has a solution for older versions of Java.

I think they used the Runtime object to execute the 'start' command on windows and there is a similar command on the mac.

l_39217_l