public InputStream getResourceAsStream ( Class className, String name){
InputStream in = null;
in = className.getClassLoader().getResourceAsStream(name);
return in;
}
className : loaded class using Class.forName().
name : name of the resource present in the same directory.
Problem : result is always null.
Could anyone tell me what is wrong with the above code though I have tried many ways.
had been facing the same problem a few days ago myself. But i found that the way i passed the name was wrong. i mean i had messed up with the relative path and absolute path. if its unable to find the name then it will throw a nullpointerException.
To check if your code is fine and the problem is only with the name, Just hard code the entire path for the name and make sure it loads. If that is so, then its just apath issue that u have to rectify. Secondly, the only other problem is if you are loading it from static block then the syntax might differ a bit. Else there should be no problem.
A good place where in u can check out the loading of file is
http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html?page=2
let me know if this helps..