aspose file tools*
The moose likes Beginning Java and the fly likes [SOLVED]Using resources in the classpath throws FileNotFoundEx if there are spaces in the path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "[SOLVED]Using resources in the classpath throws FileNotFoundEx if there are spaces in the path" Watch "[SOLVED]Using resources in the classpath throws FileNotFoundEx if there are spaces in the path" New topic
Author

[SOLVED]Using resources in the classpath throws FileNotFoundEx if there are spaces in the path

Karim Hamamouch
Greenhorn

Joined: Jun 07, 2011
Posts: 5

Hi,

I'm writing a simple program that loads a conf file but it doesn't work (throws a FileNotFoundException if there are spaces in the path of the project (working on Windows Seven).
I checked by moving my project to another location without spaces in the path and it's working.

Question is, why doesn't it work and how can I prevent that to happen ? (I want to name my paths as I wish :p )



Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

You shouldn't treat the resource as a File because it usually isn't - usually, resources are entries inside JAR files. Use getResourceAsStream instead of getResource, then use an InputStreamReader around the resulting InputStream:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Karim Hamamouch
Greenhorn

Joined: Jun 07, 2011
Posts: 5

You made my day Rob, thanks a lot (for the explanation too, since I often use Spring and don't want to for a playing project)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [SOLVED]Using resources in the classpath throws FileNotFoundEx if there are spaces in the path