title: java.nio.file.NoSuchFileException When File.transferTo() is called
body: <p>I've recently inherited a Java API and am having trouble with file uploads. Unfortunately, Java isn't a language I have much experience in so I'm a bit stumped by this.</p>
  
  <p>The <code>MultiPartFile</code> is being received ok, and I can find the file in the temp directory, but when I try to use File.transferTo() to create the final file I just get the below error;</p>
  
  <blockquote>
    <p>java.nio.file.NoSuchFileException: C:\Users\myUser\AppData\Local\Temp\undertow3706399294849267898upload -> S:\Dev\PolicyData\Temp.xlsx</p>
  </blockquote>
  
  <p>As I mentioned the temp undertow file exists, and the directory on the S drive also exist, (but there's no Temp.xlsx as my understanding is this should be created by <code>transferTo()</code>). Any solutions I've found to this problem so far are resolved using absolute file paths.</p>
  
  <p>This is a simplified version of the code but the error remains the same.</p>
  
  <p>SpringBoot framework is "1.5.3.RELEASE", running Java 1.8.0_131</p>
  
  <pre><code>    ResponseEntity handleFileUpload(@RequestPart(name = "file") MultipartFile file, @PathVariable Long stageFileTypeId) {
      if (!file.isEmpty()) {
          try {
              String filePath = "S:\\Dev\\PolicyData\\Temp.xlsx";
              log.info("Upload Path = {}", filePath);
  
              File dest = new File(filePath);
              file.transferTo(dest);
  
              return ResponseUtil.wrapOrNotFound(Optional.ofNullable(filePath));
          }
          catch (Exception ex) {
              log.error("An error has occurred uploading the file", ex);
              return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
          }
      }
      else {
          log.error("An error has occurred, no file was received");
          return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
      }
  }
  </code></pre>
  
  <p>If you need any more information please let me know.</p>
  
  <p>Thanks,
  Neil</p>