Question: I'm trying to read a file from
the jsp file on the server. It works fine when I try to read the same file on my
PC with the following statement:
FileReader f = new FileReader("d: empa.txt");
BufferedReader fi = new BufferedReader(f);
However, when I run the same JSP file with the same statement on the server, I
get the exception saying that the file cannot be found...
I am sure that the file file is in the same directory as the JSP file that tries
to open it.
FileReader f = new FileReader("a.txt");
BufferedReader fi = new BufferedReader(f);
Here is the error when the above is executed by JSP on the server:
Answer: The JSP is not in the same directory
as the text file. The JSP is stored in a default location within the
server itself because it is compiled to a servlet.
You have two options:
1. Find this location and put your text file there,
or
2. Provide the full path to file reader the full path or give it a relative path
(the best choice, since the code will be portable.
***************************************
Our older tips: March 22, 2001 - Oktober 21, 2002
read here.
All published and not published on site tips you can find
here
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.