I have a Java Servlet that produces an HTML form. It asks the user to
input a file using standard input tags:
<input type="file" size=75 name=fileInput>
Once the form is submitted, it calls a different servlet that processes
all the data. The only problem I am having is saving the client's file
on the server. A FileNotFound exception is thrown when the servlet
tries to save the file in a new location. Here is a snippet of my
code:
File newFile = new File(serverFileLoc, fileName);
temp = req.getParameterValues("fileInput");
File origFile = new File(temp);
InputStream ins = new FileInputStream(origFile);
OutputStream outs = new FileOutputStream(newFile);
byte[] buf = new byte[1024];
int len;
while ((len = ins.read(buf)) > 0)
{
outs.write(buf, 0, len);
}
ins.close();
outs.close();
Everything works fine when run locally, but when run from a client
machine, it fails when I create the FileInputStream due to a
FileNotFoundException.
Any ideas?
I would greatly appreciate anyone that could help me solve this
problem. Thanks, Matt
Vincent van Beveren - 25 Jul 2006 08:35 GMT
> Any ideas?
What package do you use to process the upload? CommonsUpload, COS?
Home-made solution? The default servlet spec does not handle mutlipart
uploads, so you'll have to use a 3rd party library to make it work.
Vincent
jvsoft.org@gmail.com - 25 Jul 2006 13:25 GMT
> > Any ideas?
>
[quoted text clipped - 3 lines]
>
> Vincent
Just download a copy of 'java upload bean",it's free
<a
href="http://www.developerzone.biz/index.php?option=com_content&task=view&id=151&Itemi
d=36">Java
Tutorials</a>