title: Servlet Upload java.io.FileNotFoundException:
body: <p>I am trying to create a upload form using servlets, and so far i have the following;</p>
  
  <pre><code>    protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      boolean isMultipart = ServletFileUpload.isMultipartContent(request);
  
      if (isMultipart) {
          FileItemFactory factory = new DiskFileItemFactory();
          ServletFileUpload upload = new ServletFileUpload(factory);
  
          try {
              List items = upload.parseRequest(request);
              Iterator iterator = items.iterator();
              while (iterator.hasNext()) {
                  FileItem item = (FileItem) iterator.next();
  
                  if (!item.isFormField()) {
                      String fileName = item.getName();
  
                      String root = getServletContext().getRealPath("");
                      File path = new File(root + "/uploads");
  
                      if (!path.exists()) {
                          boolean status = path.mkdirs();
  
                      }
  
                      File uploadedFile = new File(path + "/" + fileName);
                      System.out.println(uploadedFile.getAbsolutePath());
                      item.write(uploadedFile);
  
                  }
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>It seems to upload the files fine, however it always throws a java.io.FileNotFoundException: 
  Have i done something wrong?</p>
  
  <p>ERROR:</p>
  
  <pre><code>    /Applications/Tomcat/apache-tomcat-6.0.35/wtpwebapps/work/uploads/texsxxdddst.xml
  /Applications/Tomcat/apache-tomcat-6.0.35/wtpwebapps/work/uploads
  java.io.FileNotFoundException: /Applications/Tomcat/apache-tomcat-6.0.35/wtpwebapps/work/uploads (No such file or directory)
      at java.io.FileOutputStream.open(Native Method)
      at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:194)
      at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:145)
      at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:426)
      at servlets.uploadServlet.doPost(uploadServlet.java:48)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      at java.lang.Thread.run(Thread.java:680)
  </code></pre>