Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

russellelly

macrumors regular
Original poster
Jun 23, 2006
139
41
Glasgow, UK
Hi all,

Just spent some hours banging my head on a brick wall with this one. I've got a program where I have to open a file given its pathname as a String. I've got code that works fine on Mac and Linux, but it'll only work on Windows XP if the pathname for certain file types - for example .m4a will open with iTunes quite happily, but .avi produces this error:

Code:
java.io.IOException: Failed to open file:/C:/Documents%20and%20Settings/Chris/Desktop/In.Treatment.S01E21.avi. Error message: The parameter is incorrect.

at sun.awt.windows.WDesktopPeer.ShellExecute(Unknown Source)
at sun.awt.windows.WDesktopPeer.open(Unknown Source)
at java.awt.Desktop.open(Unknown Source)

(the stack trace goes on a while, but I won't type it all out unless more is needed)

I've tried this with the default application for .avi being Windows Media Player and VLC (that error is with the latter set, the former gives a similar but slightly different error). Does Windows XP just not fully support the java.awt.Desktop class?

Any ideas very welcome! :)
 

bloomberg

macrumors newbie
Sep 8, 2007
25
5
The first problem is that the file path separator should be a backslash on windows, not a slash. (also remember you need two of them within a string.) It's good practice to use a regular expression and replace path elements with File.separator which is cross-platform.

The second issue, but am not sure about this, is the file:/ at the beginning of your path. Not sure if this is your debugging statement or part of the path but I don't think you need it... but if you do use it, it should be file:/// on windows.

Edit: Only follow one of the two suggestions above but not both. I.e. remove the proceeding file: and use backslashes OR change it to file:///. Good luck!
 

garethlewis2

macrumors 6502
Dec 6, 2006
277
1
If you're using Unix style path seperartors that will be your problem. Rather than farting about trying to write code the determines what is running on, just use the System property "pathseperator" in Java and use this to construct the string where you want to load the file from. If that doesn't work your code is incorrect. We use that style here.
 

sord

macrumors 6502
Jun 16, 2004
352
0
Java + Windows works just fine with / instead of \ for file separators, I use them all the time at work...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.