aspose file tools*
The moose likes Struts and the fly likes Problem in Locating a properties File (Not the Struts application.properties) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem in Locating a properties File (Not the Struts application.properties)" Watch "Problem in Locating a properties File (Not the Struts application.properties)" New topic
Author

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

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
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:
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
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

Joined: Nov 19, 2000
Posts: 1309
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

Joined: Nov 19, 2000
Posts: 1309
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

Joined: Sep 21, 2003
Posts: 415
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Locating a properties File (Not the Struts application.properties)