title: Java: Using nio Files.copy to Move Directory
body: <p>I am new to the nio class, and am having trouble moving a directory of files to a newly created directory.</p>
  
  <p>I first create 2 directories with:</p>
  
  <pre><code>File sourceDir = new File(sourceDirStr); //this directory already exists
  File destDir = new File(destDirectoryStr); //this is a new directory
  </code></pre>
  
  <p>I then try to copy the existing files into the new directory, using:</p>
  
  <pre><code>Path destPath = destDir.toPath();
  for (int i = 0; i &lt; sourceSize; i++) {
      Path sourcePath = sourceDir.listFiles()[i].toPath();
      Files.copy(sourcePath, destPath.resolve(sourcePath.getFileName()));
  }
  </code></pre>
  
  <p>This throws the following error:</p>
  
  <pre><code>Exception in thread "main" java.nio.file.FileSystemException: destDir/Experiment.log: Not a directory
  </code></pre>
  
  <p>I know that <code>destDir/Experiment.log</code> is not an existing directory; it should be a new file as a result of the <code>Files.copy</code> operation. Could someone point out where my operation is going wrong? Thanks!</p>