This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can not load file  RSS feed

 
kavan desai
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends

I am trying to load property file using the following method

/* code starts */

Properties prop = new Properites();


prop.load(this.getClass().getResourceAsStream("/some path/somename.prop"));

/* code ends */

I am not able to load the file i written this code in servlet.

If i change the code as
/* code starts */
prop.load(new FileInputStream("/some path/somename.prop"));
/* code ends */

then its working fine .. but i am interested in finding the reason why the previous implementation is not wokring ?? it should work na ..

Please help me

Thanks
Kavan
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getResourceAsStream loads a file from your classpath. If the name starts with a slant then it denotes a path starting from the "root" of the class hierarchy. If the name does not start with a slant, then it denotes a path starting from the loading class' package. So, if the file is not located on your classpath, but rather somewhere else, then getResourceAsStream is not going to be able to find it. And, given the effects your seeing, that is the case.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!