Default directory structure - simple question.

I need to add a configuration file to my application.I thought about adding it to either the web or web/resources directory of my project.My question is this:How do I reference either of these directories in my File access routine?Thanks
[272 byte] By [burferda] at [2007-11-27 2:10:40]
# 1
You can just construct a File based on the given parent path and filename.Also see the [url= http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#File(java.lang.String,%20java.lang.String)]File API[/url].
BalusCa at 2007-7-12 2:03:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I guess I should have phrased my question differently.

I do not know what directory path to use in order to point to the "web" or "qeb/resources" directories.

I will have somethng like:

String path = configDir+"configFIle.cfg"

What I don't know is what to use for configDir.

configDir = ? in order to point to the project 'web' or 'web/resources'

directories.

burferda at 2007-7-12 2:03:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
You can use ServletContext#getRealPath() to retrieve the absolute path for the given relative webcontainer paths.
BalusCa at 2007-7-12 2:03:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Thanks
burferda at 2007-7-12 2:03:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

I did a little searching to find out how to use ServletContext.getRealPath and what I found is that you can't use this with a .war file since the paths are not expanded.

What I need to do is read the config file from within the war file.

There was some mention of using ServletContext.getResource(), but I'm clueless how to use that.

burferda at 2007-7-12 2:03:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Ah OK, now I see .. You can use a propertiesfile and put it in the classpath (inside a WAR, it can be the root of the package or the WEB-INF/lib directory). Then you can retrieve it by ClassLoader#getSystemResourceAsStream().

Basically:

String filename = "config.properties";

InputStream input = ClassLoader.getSystemResourceAsStream(filename);

Properties properties = new Properties();

properties.load(input);

input.close();

String someKey = properties.getProperty("someKey");

Where config.properties looks like:someKey = someValue

anotherKey = anotherValue

Also see the [url=http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html]java.util.Properties[/url] API.

BalusCa at 2007-7-12 2:03:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Thanks, I'll try that.
burferda at 2007-7-12 2:03:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...