I am trying to read a file that I have stored in
/webapps/myapp/File/AdminFile
by using the following code:
String filepath = getServletContext().getRealPath("/File/AdminFile");
//this is to insert the prefix "\\"
while ( st.hasMoreTokens() ) {
String pathElement = st.nextToken();
path.append(pathElement);
path.append(fileSeparator);
path.append(fileSeparator);
}
filepath=path.toString();
filepath=filepath.substring(0,filepath.length()-2); //this is to remove
the extra double slash
File fileToread = new File (filepath,"adminInfo.txt");
LineNumberReader br= new LineNumberReader(new FileReader(fileToread));
while ((thisLine = br.readLine()) !=null)
{....)
I am receiving error that the system cannot find the specified file.
If I copy and paste the value of the string "filepath" to the URL browser
and press enter, I am able to open the file.
I wonder where the problem lays.
My concern here is that my application should be portable.
Any help will be very much appreciated.
Bobo,
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html