title: Reading MultipartContent from a POST request
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2422468/how-to-upload-files-to-server-using-jsp-servlet">How to upload files to server using JSP/Servlet?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm implementing a fileupload servlet that is used alongside resumable.js </p>
  
  <p>Everytime I try to read a file, I either get a NoSuchElement exception or a NumberFormatException with a string inside the file I'm reading. I'm sure I made a hiccup somewhere, but can't seem to tell</p>
  
  <p>Here's a snippet of what I use to read request and write to file</p>
  
  <pre><code>if(ServletFileUpload.isMultipartContent(request)){
              DiskFileItemFactory factory = new DiskFileItemFactory();
              factory.setRepository(new File(temp_dir));
              ServletFileUpload upload = new ServletFileUpload(factory);
  
              Iterator&lt;FileItem&gt; iter = upload.parseRequest(request).iterator();
              FileItem item = iter.next();
              OutputStream out;
  
              try {
  
                  out = new FileOutputStream(new File(dest_dir));
                  IOUtils.copy(item.getInputStream(), out);
                  logger.debug("Wrote file " + resumableIdentifier + " with chunk number "
                          + resumableChunkNumber + " to " + temp_dir);
  
              } catch (FileNotFoundException fnfe) {
  
                  fnfe.printStackTrace();
  
              }
          }
  </code></pre>
  
  <p>Did I do something wrong that is making the code actually read and interpret the contents of the file?</p>