Hi Experts,
Can anyone tell me will the following code work for client-to-server file upload? Its working fine in a environment where client and server are on same machine. Somebody told me that FileInputStream does not work for client-server env. What is the solution...anyone? Thank you.
public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
String srcDir = "/Users/Downloads";
String destDir = "/Users/workspace/server/devel/soa/web/WEB-INF";
String filName = "photo.jpg";
String newName = "xyz.jpg";
try {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcDir + File.separator + filName));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destDir + File.separator + newName));
byte[] buf = new byte[1024];
int len;
while ((len = bis.read(buf)) > 0) {
bos.write(buf, 0, len);
}
bos.close();
bis.close();
} catch(IOException ioe) {
logger.error("IOEeception in UploadServlet = " + ioe.getMessage());
}
}