Uploading File Using DiskFileUpload
843841Mar 22 2004 — edited Dec 6 2005Hi,
I'm using the code snippet from the javadocs for the class org.apache.commons.fileupload.DiskFileUpload. When I run it I get a java.lang.NullPointerException (right after the fi.write() line)
Here's the code snippet:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(1000000);
fu.setSizeThreshold(4096);
fu.setRepositoryPath("c:/temp");
try {
List fileItems = fu.parseRequest(request);
Iterator i = fileItems.iterator();
FileItem fi = (FileItem)i.next();
String fileName = fi.getName();
File file=new File("c:/www/uploads/", fileName);
fi.write(file);
} catch(Exception e) {
System.out.println(e.getMessage()+" "+e.toString());
e.printStackTrace();
}
}
Any input is appreciated.
Thanks,
Ray