• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

jsf getResourceAsStream()

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic