• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Properties file not found

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does the code that tries to open the properties file look like?
 
Shaji Ravindran
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic