• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in Locating a properties File (Not the Struts application.properties)

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Struts application.properties file in my web application works OKay.

I have another file called storageDirectory.properties, which has one line:

I set my classpath to C:\jakarta-tomcat-5.0.27\webapps\AppName\WEB-INF\src\java

One of my class in the C:\jakarta-tomcat-5.0.27\webapps\AppName\WEB-INF\src\java\org\OrganizationName\content directory tries to read this storageDirectory.properties file:

I put this storageDirectory.properties in the
C:\jakarta-tomcat-5.0.27\webapps\AppName\WEB-INF\src\java directory.

I then put this storageDirectory.properties in the
C:\jakarta-tomcat-5.0.27\webapps\AppName\WEB-INF\src\java\resources directory.

No matter where I put this properties file, I get this runtime error message:
java.io.FileNotFoundException: storageDirectory.properties (The system cannot find the file specified)

And it points to this statement:
 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

once trim the string and try to read it( but i am sure that u have placed that file in classes folder rather than where ur source code is .....) and if that still doesnt work better get the absolute path using a class file in the same directory

String path=p.getClass().getResource(fileName.trim()).getPath();
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried:

Now, I got:


java.lang.NullPointerException
java.io.Reader.<init>(Reader.java:61)
java.io.InputStreamReader.<init>(InputStreamReader.java:80)
java.util.Properties.load(Properties.java:266)
org.dhsinfo.content.AddFiles.execute(AddFiles.java:40)


The error message point to this statement:

The storageDirectory.properties file is in the C:\jakarta-tomcat-5.0.27\webapps\AppName\WEB-INF\src\java\resources directory.

The classpath is C:\jakarta-tomcat-5.0.27\webapps\AppName\WEB-INF\src\java
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code works if I put the properties file in the WEB-INF\classes directory:

If I would rather put all my properties file in a folder; say, WEB-INF\classes\resources directory, is there any way to do it?
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi jai

yah u can do that place the class file which loads the proprties file in the same directory r user relative ....see it should not be placed in src directory bcoz the code will be executed from the classes directory so obviously it will look in to classed untill unless u have hardcoded the path of the properties files to src
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic