• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Hakim Benhamadouche
Greenhorn
Posts: 5
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Hakim Benhamadouche
Greenhorn
Posts: 5
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic