users@glassfish.java.net

Re: pls help, file upload to a local directory

From: <glassfish_at_javadesktop.org>
Date: Thu, 19 Apr 2007 10:11:32 PDT

String DESTINATIONDIR = "e://temp//";

boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
} else {
    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    List items = null;
    try {
           items = upload.parseRequest(request);
    } catch (FileUploadException e) {
           e.printStackTrace();
    }
    Iterator itr = items.iterator();
    while (itr.hasNext()) {
        FileItem item = (FileItem) itr.next();
        if (item.isFormField()) {
        } else {
            try {
                   String itemName = item.getName();
                   File savedFile = new File(DESTINATIONDIR+itemName);
                   item.write(savedFile);

            } catch (Exception e) {
                   e.printStackTrace();
            }
        }
    }
}
[Message sent by forum member 'arckjmaster' (arckjmaster)]

http://forums.java.net/jive/thread.jspa?messageID=213233