• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading a File in a JSF project.

 
Tiago Domingues
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there.

I can´t read a txt file in the WEB-INF folder, with FacesContext.getCurrentInstance.getExternalContext.getResourceAsStream...
Am i missing something ?

James
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, to be pedantic, that wouldn't be a literal file in any case. According to the J2EE spec, a deployed webapp is a WAR file, and this would just be one of the objects within the WAR that, if the WAR is unzipped would become an independent file.

There are 2 most likely causes for your problem. One is if you're asking for a FacesContext outside of the JSF context. In which case, you'd get a NullPointer.

The other is failure to specifiy the resource location properly on the getResourceAsStream request. The resource location is relative to the WAR, not the URL, so the proper value would be "/WEB-INF/myfile.txt" or something similar.

And, although you're evidently not intending to do so, I should repeat that old warning that WRITING to anything in a WAR is something that should not be done!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic