hi,
i try to read a file from a servlet (on the server side) and i get the error:
Error: 500
Internal Servlet Error:
java.io.FileNotFoundException: http:localhost:8080\chat\servlet\fichierALire.txt (The system cannot find the path specified)
i guess that's a problem of path but i don't understand: i put the file on the same directory as the servlet that i call.
Thanks a million for your time .
Here is the code:
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException{
PrintWriter servout = res.getWriter();
String nomFic = "http:localhost:8080/chat/servlet/fichierALire.txt";
File fichier = new File(nomFic);
FileReader fin = new FileReader(fichier);
char c[] = new char[(char)fichier.length()];
int i;
i = fin.read(c);
String s = new String(c);
res.setContentType("text/html");
servout.println( "<html>" );
servout.println( "<body bgcolor=white text=red>");
servout.println( "Results:<p>" + s +"</P>");
servout.println( "</html>");
fin.close();
}
-
reading a file from a servlet (5 messages)
- Posted by: sdg sdfgsqfg
- Posted on: March 22 2001 14:36 EST
Threaded Messages (5)
- reading a file from a servlet by sandy hoang on March 22 2001 15:19 EST
- reading a file from a servlet by John Yost on March 22 2001 17:59 EST
- reading a file from a servlet by kiran killedar on March 27 2001 05:49 EST
- reading a file from a servlet by Richard Holly on March 29 2001 03:47 EST
- reading a file from a servlet by Richard Holly on March 29 2001 03:48 EST
-
reading a file from a servlet[ Go to top ]
- Posted by: sandy hoang
- Posted on: March 22 2001 15:19 EST
- in response to sdg sdfgsqfg
Try using the absolute path of the file that you want to read. -
reading a file from a servlet[ Go to top ]
- Posted by: John Yost
- Posted on: March 22 2001 17:59 EST
- in response to sdg sdfgsqfg
-
reading a file from a servlet[ Go to top ]
- Posted by: kiran killedar
- Posted on: March 27 2001 05:49 EST
- in response to John Yost
hi,
try to use actually system path like c:\test.txt ithink this should help u.
bye
-kiran -
reading a file from a servlet[ Go to top ]
- Posted by: Richard Holly
- Posted on: March 29 2001 03:47 EST
- in response to sdg sdfgsqfg
hi
if you want to keep your path , is better to use :
URLConnection con = new URLConnection("http:localhost:8080/chat/servlet/fichierALire.txt");
InputStream in = con.getInputStream();
... continue like with file -
reading a file from a servlet[ Go to top ]
- Posted by: Richard Holly
- Posted on: March 29 2001 03:48 EST
- in response to sdg sdfgsqfg