title: Uploading a file with httpservlet to java.io.tmpdir through part.write - to an absolute tmp path
body: <p>I am trying to make a servlet to upload a file to a temporary location. When I build the file path everything seems alright.</p>
  
  <blockquote>
    <p>String uploadFilePath = System.getProperty("java.io.tmpdir") + File.separator + UPLOAD_DIR;</p>
  </blockquote>
  
  <p>and I get the absolute path: C:\Users\victor\AppData\Local\Temp\uploads</p>
  
  <p>but when I call </p>
  
  <blockquote>
    <p>part.write(uploadFilePath + File.separator + fileName);</p>
  </blockquote>
  
  <p>I get:
  C:\Users\victor\GlassFish_Server\glassfish\domains\domain\generated\jsp\pcpweb\ <strong>C:\Users\victor\AppData\Local\Temp\uploads</strong></p>
  
  <p>and an java.io.FileNotFoundException afterwards, far enough I guess. </p>
  
  <p>So "write" is completing my path. I there a way to avoid this?
  Thanks.</p>
  
  <p>Using: glassfish and netbeans</p>
  
  <pre><code>    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
  
      // constructs path of the directory to save uploaded file
      String uploadFilePath = System.getProperty("java.io.tmpdir") + File.separator + UPLOAD_DIR;
  
      // creates the save directory if it does not exists
      File fileSaveDir = new File(uploadFilePath);
      if (!fileSaveDir.exists()) {
          fileSaveDir.mkdirs();
      }
      System.out.println("Upload File Directory=" + fileSaveDir.getAbsolutePath());
  
      String fileName = null;
      //Get all the parts from request and write it to the file on server
      for (Part part : request.getParts()) {
          fileName = getFileName(part);
          part.write(uploadFilePath + File.separator + fileName);
      }
  
      request.setAttribute("message", fileName + " File uploaded successfully!");
      getServletContext().getRequestDispatcher("gerencia.jsp").forward(
              request, response);
  }
  </code></pre>