Read text file in JSF WebContent folder

Ok, so I am trying to retrieve and read a text file that is in a WebContent/resources/ folder in my JSF project and I have no idea how to get the relative path to if from my backing bean... Any Suggestions on how to go about retrieving and reading this file?

enter image description here

Upvotes: 1

Views: 6085

Answers (2)

Alexandre Lavoie
Alexandre Lavoie

Reputation: 8771

You can read your file with resource functions as described in this answer :

How to reference file resource in a JSF Application

InputStream stream = FacesContext.getCurrentInstance().getExternalContext()
.getResourceAsStream("/foo.xsd");

Upvotes: 0

Stéphane
Stéphane

Reputation: 877

((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext()).getRealPath("/resources/")

will give you the file system path of the resources folder.

Upvotes: 3

Related Questions