Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Properties file not found

 
Shaji Ravindran
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the code that tries to open the properties file look like?
 
Shaji Ravindran
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the responses, i got it working using the following code
InputStream is = getClass().getClassLoader().getResourceAsStream("prop.properties");
properties.load(is);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic