Java Web Application - Get the current dir / Read a text file

Does anyone know how can I read a text file from my JSF/ICEFACES website and put it content in an inputTextArea?
I'm doing this:
<ice:inputTextarea readonly="true" value="#{BCad.termos}"/>

where BCad is my backing bean and termos is the property that reads the textfile and return its content. The only way I found over the internet to read a text file is by using BufferedReader, that needs a FileReader which one needs the path to the file to be read. The problem is that I don't know what path it is in.. neither should know.. I want to give it like a web path in relationship to the root path of the website for example. e.g.: if the directory of the index is c:\mywebsite\index.jspx, and the text file is in c:\mywebsite\texts\mytext.txt so I should inform it as /texts/mytext.txt. Or it could be any way that I can give the current path of the website and use it to locate the text file; the way I found over the internet, to do this, is by System.getProperty("user.dir"); but this give me the path of the tomcat BIN directory.
Who is Participating?
mnrzConnect With a Mentor Commented:
if you access the servlet Contex you can achieve the real path

assume the you have servletContext

will return the complete path of your file and you can load it by any File reader.

because you are using JSF I think you can get the servlet context by FacesContext object
try this:

String ctxPath = request.getContextPath();

hth :)
SkyW4rriorAuthor Commented:
Thank you very much. Worked fine!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.