title: AccessDeniedException on Files.copy from a temporary file in Java NIO2
body: <p>I am getting used to Java 7 and the new <code>Files</code> class.</p>
  
  <p>I am writing a small application which, at some point, must replace the contents of a file. 
  I used a temporary file to avoid erasing the target file if somethign goes wrong. However, I'm always getting an <code>AccessDeniedException</code> when performing the actual copy.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>// Temporary file generation.
  Path target = getCurrentConfigFile(); // Returns a path, works ok.
  Path tempFile = Files.createTempFile("tempfile", null);
  Files.write(tempFile, conf.getBytes(Charset.defaultCharset()), StandardOpenOption.WRITE);
  
  // Actual copy.
  Files.copy(tempFile, target, StandardCopyOption.REPLACE_EXISTING);
  
  // Cleanup.
  Files.delete(tempFile);
  </code></pre>
  
  <p><code>getCurrentConfigFile()</code> handles the target file Path creation:</p>
  
  <pre><code>(... generates various strings from configuration parameters)
  return FileSystems.getDefault().getPath(all, these, various, strings);
  </code></pre>
  
  <p>When I execute the code, it's through a <code>.bat</code> script, and I get the error both with a standard Command Prompt or elevation. 
  The target file is in <code>C:\temp\tests</code>, a directory I created with the same Windows user.</p>
  
  <p>It seems the problem lies in reading from the temporary file, as writing directly to the target works.
  Where should I look next?</p>