• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

relative path name for propertiesObject.load()

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem constructing a new FileInputStream for use in a propertiesObject.load() method.
The code is:
Properties dbProps = new Properties();

try
{
dbProps.load(new FileInputStream("c:/program files/allaire/jrun/servers/default/Tods/web-inf/classes/db.properties"));

}
catch(FileNotFoundException e)
{
toadPackage.Debug.p("Could not find properties file ");
throw new ProccessException("could not find properties file:" + e);
}
catch(IOException e)
{
toadPackage.Debug.p("Error reading form properties file ");
throw new ProccessException("Error proccessing properties file:" + e);
}
As you can see, this is ugly and inflexible. The problem is that I do not want to specify a full hardcoded pathname for the constructor of the FileInputStream.
I am using JRun 3.0.
I have tried multiple variations of relative path names including the app's URI etc. and nothing seems to work. It can never find my file unless I hardcode the full path name. Anybody know how I can fix this?
 
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
I scored this handy hint off the Tomcat mailinglist:
InputStream is = getClass().getResourceAsStream("/rollout.properties");
Properties props = new Properties();
try
{
props.load(is);
}
catch (Exception e)
{
Where you keep your properties file in the classes directory.
This works because the class loader knows where the class came from.
Bill
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found that with JRun I can put property files in the servers\default directory and can access them with no path information, but just the name of the file:
String propertyFile = "project.properties";
props = new Properties();
try {
FileInputStream fin = new FileInputStream(propertyFile);
props.load(fin);
fin.close();
} catch (Exception e) {}
That may not be a great place to keep property files, but it seems to work
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just so you know - newbies do know how to do searches before we ask newbie questions. thankfully, my question had already been answered here. Thanks, William!
------------------
www.rusmo.com
 
reply
    Bookmark Topic Watch Topic
  • New Topic