You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Caroline Jen <ji...@yahoo.com> on 2004/10/19 17:44:35 UTC

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

The application.properties file in my web application
works OKay.

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

outputFile =
C:\\jakarta-tomcat-5.0.27\\webapps\\AppName\\var\\

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:

final String PROPFILE = "storageDirectory.properties";
Properties oProp = null;
       
FileInputStream fis = new FileInputStream( PROPFILE );
oProp = new Properties();
oProp.load ( fis );

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:
FileInputStream fis = new FileInputStream( PROPFILE );


		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problem in Locating a properties File (Not application.properties)

Posted by nitin dubey <ni...@yahoo.com>.
Caroline,

You need to use getResourceAsStream() method from
ServletConfig class.

request.getSession().getServletContext().getResourceAsStream("/filename.properties");

This will return you an InputStream that you can pass
to Properties.loadProperties() and make it work.

The "/" represents the context root.


Nitin
--- Caroline Jen <ji...@yahoo.com> wrote:

> The application.properties file in my web
> application
> works OKay.
> 
> I have another file called
> storageDirectory.properties, which has one line:
> 
> outputFile =
> C:\\jakarta-tomcat-5.0.27\\webapps\\AppName\\var\\
> 
> 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:
> 
> final String PROPFILE =
> "storageDirectory.properties";
> Properties oProp = null;
>        
> FileInputStream fis = new FileInputStream( PROPFILE
> );
> oProp = new Properties();
> oProp.load ( fis );
> 
> 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:
> FileInputStream fis = new FileInputStream( PROPFILE
> );
> 
> 
> 		
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org