Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsf getResourceAsStream()

 
Bill Zelan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic