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]

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 >

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.
>
> 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");