Copying Files with Spaces

2019-09-02 04:33发布

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.

3条回答
欢心
2楼-- · 2019-09-02 05:12

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

查看更多
贼婆χ
3楼-- · 2019-09-02 05:25

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.

查看更多
疯言疯语
4楼-- · 2019-09-02 05:36

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_1.html

查看更多
登录 后发表回答