| Author |
Reading a File in a JSF project.
|
Tiago Domingues
Greenhorn
Joined: Jan 26, 2011
Posts: 1
|
|
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
Joined: Jun 25, 2001
Posts: 14475
|
|
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!
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
 |
|
|
subject: Reading a File in a JSF project.
|
|
|