File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes jsf getResourceAsStream() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "jsf getResourceAsStream()" Watch "jsf getResourceAsStream()" New topic
Author

jsf getResourceAsStream()

Bill Zelan
Ranch Hand

Joined: Jan 09, 2009
Posts: 46
I am trying to read a properties file in my web application. Whenever I try to read the file I get a null pointer exception. The code that is causing the problem is pasted below.


Annu Vinayak
Greenhorn

Joined: Jul 17, 2009
Posts: 19
Hi,

You have to laod the resource bundle for the properties file first.

Try this:

ResourceBundle resourceBundle = ResourceBundle.getBundle( propertyFileName);

Now whenver you need to access a key from the properties file use:

return (String) resourceBundle.getObject(key);
Bill Zelan
Ranch Hand

Joined: Jan 09, 2009
Posts: 46
No I don't think that is the problem. It seems to be an issue with the way tomcat handles files in the web app (exploded or in a war). I don't think tomcat can locate the resource. All the java files in tomcat get placed in the build directory in the corresponding package, so what relative or absolute path do I have to use to point to files in the WEB-INF directory?
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Hi,
I've a question related to FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream() function, it returns only the web application name as string and I wanna to get a property file read from WEB-INF folder. But throws null pointer exception when I not give path to getResourceAsStream("/WEB-INF/A.properties").

I hope the WEB-INF folder is added with the web application's class path, so it has to retrieve the file right? Kindly clarify me. Thanks in advance.


No pain, No gain.
OCJP 1.6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsf getResourceAsStream()