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
2009-02-15 04:44:01
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
2009-02-15 19:30:53
Can you provide your code in the question? Also, which OS and Java version are you using?
Zach Scrivena
2009-02-15 19:36:06
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
2009-02-17 02:03:41
oh and btw, file.exist() == true
Frederic Morin
2009-02-17 02:04:18
@Blade: Could you try file.getCanonicalFile() to see if there's a difference?
Zach Scrivena
2009-02-17 03:13:52
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
2009-02-24 20:29:31
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
2009-04-04 01:33:52
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
2009-05-22 14:05:16