views:

56

answers:

3

My apologies if this is too simple a question, I was unable to google it as it did not like searching for %20.

If I have a URL on which I use the getFile() method to obtain the path for a file I would like to open for processing. If the particular file resides in a directory that contains spaces, the path returned would contains %20 where the space should be.

Will a FileReader then be able to use the path as provided, or will I need to replace the %20 with a space?

+2  A: 

Use URLDecoder.decode() to decode a path

axtavt
+3  A: 

You will need to use URLDecoder yourself. FileReader just uses the String it's handed, and rightly so - %20 is a perfectly valid character sequence in a file name, and if it were automatically converted you could not access files containing it.

Michael Borgwardt
A: 

If you downloaded the file, and saved it on local file system. And you are using FileReader to read it as

FileReader fr = new FileReader(new File(url.getFile()));

Yes File, can understand URL encoding. So you don't need to decoded it. If you decoded it as others have suggested it will be more readable when you print the file path.

chinmaya