H
hust6
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
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