title: How to move all files from source directory to destination directory, keeping existing files in destination directory, using Java NIO?
body: <p>I am using Java 8 in Windows, I am trying to achieve one simple thing. Say I have a <code>source</code> directory and a <code>destination</code> directory. I am trying to move files from source to destination in a daily basis. Below is a simple java code, using NIO;</p>
  <pre><code>Path sourcePath = Paths.get(&quot;C:\\source&quot;);
  Path destinationPath = Paths.get(&quot;C:\\destination&quot;);
  try {
      Files.move(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING);
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  <p>In the first run, this will work fine, because the destination is empty. On the second run, or if the destination is not empty, NIO will throw an exception;</p>
  <pre><code>java.nio.file.DirectoryNotEmptyException: C:\destination
      at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:373)
      at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
      at java.nio.file.Files.move(Files.java:1395)
      at instacopy.Test.main(Test.java:14)
  </code></pre>
  <p>What I am trying to achieve is;</p>
  <ol>
  <li>New files should be moved from source to destination.</li>
  <li>If file with same name exists in destination, it should be replaced with the new one.</li>
  </ol>
  <p>Is this possible? If yes, how can I do this?</p>