aspose file tools*
The moose likes Tomcat and the fly likes Properties file not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Properties file not found" Watch "Properties file not found" New topic
Author

Properties file not found

Shaji Ravindran
Ranch Hand

Joined: Jan 12, 2002
Posts: 39
Hi,
Iam running an web application on jakarta-tomcat-5.0.16 which is using property file but the java file is not able to pick the properties file.My java classes are in the package com.export. in WEB-INF\classes\com\export folder and i have put my property file named prop.properties in WEB-INF\classes folder as well as the WEB-INF\classes\com\export folder also, but when i acess the site from browser its showing
java.io.FileNotFoundException: prop.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
If anyone could help me get this working, I would be most appreciative.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
What does the code that tries to open the properties file look like?
Shaji Ravindran
Ranch Hand

Joined: Jan 12, 2002
Posts: 39
Hi,
Thanks for the response.The code is
Properties properties = new Properties();
try
{
properties.load(new FileInputStream("prop.properties"));
}
catch(Exception e)
{
e.printStackTrace();
}
When i runs this from console as standalone applications, it works fine,but its not working in tomcat.
[ February 13, 2004: Message edited by: Shaji Ravindran ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
The code
depends on the "current" directory so it will work when you run it stand-alone from the directory where prop.properties lives. You can't count on the "current" directory in a servlet situation.
You have to provide either an absolute file location with FileInputStream or a web-application relative location with (ServletContext) getResourceAsStream
Bill
Shaji Ravindran
Ranch Hand

Joined: Jan 12, 2002
Posts: 39
Hi,
Thanks for the responses, i got it working using the following code
InputStream is = getClass().getClassLoader().getResourceAsStream("prop.properties");
properties.load(is);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Properties file not found
 
Similar Threads
Difficulty in adding own manifest file
jar files in vista business
where to put log4j.properties?
my program can not write in own file with tomcat5.32 + cpanel
Getting java.io.FileNotFoundException while using jar