• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can not load file

 
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!