Old problem of properties file not found

hi,

It seems my problem is very common and got many results when searched in the forum...still my problem is not solved.

I have a properties file which has to be read through the classes packaged in the webinf / classes folder and i dont want to mention absolute path in my program. The steps as suggested in the forum were

1) Place the properties file in the webinf / classes folder

2) Get the inputstream using this.getClass().getClassLoader().getResourceAsStream("abc.properites");

Still i am getting the inputstream as null when i tried to print it out.

Please guide me through the correct steps

thanx

[654 byte] By [.@_a] at [2007-10-2 20:24:08]
# 1
Do you take the package structure into account?
BIJ001a at 2007-7-13 23:06:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I tried two alternatives....both attempts got failed

1) Place the abc.properties file in webinf / classes folder and from the class file i called this.getClass().getClassLoader().getResourceAsStream("ams.properites")

2) Placed the properties file in webinf / classes / com directory and called

this.getClass().getClassLoader().getResourceAsStream("com/ams.properites")

Both the attempts resulted in failure. I hope this clarifes my question.

P.S : I am using Netbeans 5.0 IDE

.@_a at 2007-7-13 23:06:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
hurrrray.... I got my problem solved using ResourceBundle code posted at http://forum.java.sun.com/thread.jspa?forumID=33&threadID=474715 thread.Thanx for ResourceBundle...and thanx to BIJ001 for your response
.@_a at 2007-7-13 23:06:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Just for the sake of reference for others who may read this thread - in a web application its preferable to use the ServletContext's getResourceAsStream(String path) method to load a property file irrespective of whethere its avilable as an exploded directory structure or as a war file.

The path should begin with a '/' and refers to the context root. Thus if you have a file say config.properties in the WEB-INF/classes folder, you would

Properties myProps = new Properties();

InputStream is = getServletContext().getResourceAsStream("/WEB-INF/classes/config.properties");

myProps.load(is);

And if its in say a custom folder called 'config' directly under the web root, you need to change the path to

InputStream is = getServletContext().getResourceAsStream("/WEB-INF/config/config.properties");

ram.

Madathil_Prasada at 2007-7-13 23:06:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

>

> And if its in say a custom folder called 'config'

> directly under the web root, you need to change the

> path to

>

> > InputStream is =

> getServletContext().getResourceAsStream("/WEB-INF/conf

> ig/config.properties");

>

>

> ram.

Sorry that ought to be

InputStream is = getServletContext().getResourceAsStream("/config/config.properties");

Madathil_Prasada at 2007-7-13 23:06:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...