Link to home
Start Free TrialLog in
Avatar of SkyW4rrior
SkyW4rrior

asked on

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.
Avatar of ayeen
ayeen
Flag of United States of America image

try this:

String ctxPath = request.getContextPath();

hth :)
ASKER CERTIFIED SOLUTION
Avatar of mnrz
mnrz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SkyW4rrior
SkyW4rrior

ASKER

Thank you very much. Worked fine!