how to read a properties file from a jsf project...

Hello!

I'm new to jsf. I've created a properties file named configuration.properties under the WEB-INF folder.

From a java class located in com.mycomp.utils I try to read the properties

Properties p=new Properties();

p.load(new FileInputStream("/WEB-INF/configuration.properties"));

but the file is not found.

How can I actualy get the correct path of the file and make the things work?

Thanks

Sorin

[550 byte] By [Sorin_Ciolofana] at [2007-11-27 10:56:11]
# 1

Place the configuration file under the /WEB-INF/classes directory and use the following code:

p.load(Thread.currentThread()

.getContextClassLoader()

.getResourceAsStream("configuration.properties"));

or if you can get by with a ResourceBundle:

ResourceBundle r = ResourceBundle.getBundle("configuration");

RaymondDeCampoa at 2007-7-29 12:01:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Rather use the 1st suggestion of ClassLoader#getResourceAsStream().

ResourceBundle is initially to be used for localized messages.

BalusCa at 2007-7-29 12:01:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Thanks. I've used the first approach and it worked

:-)

Sorin_Ciolofana at 2007-7-29 12:01:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...