views:

181

answers:

3

I'm trying to copy one file to another directory, but the way I am copying the file is not working when the source path has a directory with spaces in it, e.g.

/Volumes/public/Music/Directory With Spaces/01.mp3

I am using: http://commons.apache.org/io/

I can't find a way around this, any ideas?

Edit: The problem should probably be putting paths with spaces into a java.io.File object.

+2  A: 

If you are using version 1.1, then you should be able to use '%20' to refer to a space.

Source: http://commons.apache.org/io/upgradeto1%5F1.html

Will Bickford
A: 

If you create a java.io.File object with the directory you stated, does it find it? Does it find the file (i.e. file.exists() returns true)? My thought is that you need to encode it in a File object, or a URI/URL object. However, I am not intimately familiar with the Apache IO libraries, as I tend to use the standard ones in the Java releases.

If the path works with the standard Java IO libraries, then that would point to some different handling with the Apache IO libraries. If it doesn't, I would attempt to get it working with those first, and then use a File object to get it working fully.

aperkins
Doing file.exists() throws false. Using both %20 or escaped spaces fails for the path for java.io.File.
Take a look at David Mole's comments - it sounds like there is something that is different from what you are expecting.
aperkins
A: 

Try it with escaped spaces: /Volumes/public/Music/Directory\ With\ Spaces/01.mp3

Nilloc
Doesn't like that either. That was my first idea, but nothing different.