Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Uploading File Using DiskFileUpload

843841Mar 22 2004 — edited Dec 6 2005
Hi,

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

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 3 2006
Added on Mar 22 2004
7 comments
331 views