This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 19656
    
  18

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
 
Similar Threads
Class.getResourceAsStream() returns null in Eclipse
Error 405 with HttpUrlConnection when request web service
How to load a file in jar file
Problem inputting and outputting strings correctly (weird error)
Writing a class file to read text file.