Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • 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:
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic