GeeCON Prague 2014*
The moose likes JSP and the fly likes java.io.FileNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "java.io.FileNotFoundException" Watch "java.io.FileNotFoundException" New topic
Author

java.io.FileNotFoundException

gino mendoza
Greenhorn

Joined: Jul 12, 2002
Posts: 20
i'm a beginner and i'm pretty sure this is a very basic question.
i have a form in A.html.
the user enters a filename, e.g. C:\list.txt
then control passes on to a JSP page, B.jsp
my code in B.jsp says:
String sFilename = null;
sFilename = request.getParameter("filename");
File myFile = new File(sFilename);
BufferedReader in = new BufferedReader(new FileReader(myFile));
....
However, I get the ff: exception:
java.io.FileNotFoundException: C:/list.txt (No such file or directory)
I am sure the file is there.
What am I missing?
Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61306
    
  66

If "C:\list.txt" is located on the client machine, keep in mind that your JSP pages are executing on the server. So your JSP is looking for the file on the server and not on the client.
If you are trying to upload a file from the client to the server, you'll need to look into using the file input element in a multi-part form, and coding a servlet to handle the upload.
There are available components to help you do this... search these forums for "file upload" for more info.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
gino mendoza
Greenhorn

Joined: Jul 12, 2002
Posts: 20
you're exactly right.
i used the oreilly package to do the file upload, then the JSP reads that uploaded file.
has anyone used the oreilly package before.
will that file that I uploaded reside on the server now or is it only when I used it.
if it got stored, how can I delete it from the server. i don't want to save files on the server, just to rbing them up to ther server, read them and process, then delete/release the file.
thanks
Sudarshan Reddy
Greenhorn

Joined: Aug 23, 2007
Posts: 20
any one have the sample code uploading the file to the server from the client machine by using the third party tool..?

thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61306
    
  66

See the JSP FAQ where this is covered.

And, in the future, please start a new post rather then resurrecting a 6-year-old post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.FileNotFoundException