Two Laptop Bag
The moose likes Servlets and the fly likes relative path for .properties file .. pls help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "relative path for .properties file .. pls help" Watch "relative path for .properties file .. pls help" New topic

relative path for .properties file .. pls help

Chuan Ren
Ranch Hand

Joined: Aug 04, 2003
Posts: 42
I am using Tomcat 4.1 with J2SDK 1.3.1_08. I have setup a context in
The file is located in:
and in
My question is, how could I put the into say /WEB-INF/config
without having to specify the fullpath ('coz the instance name could change).
final String configFile= "../config/";
does not seems to work.
Thank you.
import java.util.*;

public class LoadProperties {
static void displayValue() {
final String configFile = "C:/1LMS/web-app/WEB-INF/classes/";
Properties Prop = new Properties();
try {
FileInputStream configStream = new FileInputStream(configFile);
} catch(IOException e) {
System.out.println("Error: Cannot laod configuration file ");
final String PathImage =Prop.getProperty("ImagePath");
final String PathJsp = Prop.getProperty("JspPath");
System.out.println("ImagePath = " + PathImage);
System.out.println("JspPath = " + PathJsp);

} // displayValue

static public void main(String[] args) {
} // main
} // class
Timo Hahn

Joined: Jul 26, 2002
Posts: 10
there are two solutions.
1. if you are using a servlet you can use

2. get the path via the classloader

where the starting point is the classes directory in the Web-Inf folder
Chuan Ren
Ranch Hand

Joined: Aug 04, 2003
Posts: 42
Thank you. That works.
I agree. Here's the link:
subject: relative path for .properties file .. pls help
It's not a secret anymore!