title: Moving files from one directory to another with Java NIO
body: <p>I am using the NIO libraries but I am getting a strange error when I try to move files from one directory to another.  </p>
  
  <pre><code>String yearNow = new SimpleDateFormat("yyyy").format(
      Calendar.getInstance().getTime());
  
  try {
       DirectoryStream&lt;Path&gt; curYearStream = 
         Files.newDirectoryStream(sourceDir, "{" + yearNow + "*}"); 
         //Glob for current year
  
       Path newDir = Paths.get(sourceDir + "//" + yearNow);
  
       if (!Files.exists(newDir) || !Files.isDirectory(newDir)) {
           Files.createDirectory(newDir); 
           //create 2014 directory if it doesn't exist
       }
  }
  </code></pre>
  
  <p>Iterate over elements that start with "2014" and move them in the new directory (newDir, which is also called 2014)</p>
  
  <pre><code>for (Path p : curYearStream) {
      System.out.println(p); //it prints out exactly the files that I need to move
      Files.move(p, newDir); //java.nio.file.FileAlreadyExistsException
  }
  </code></pre>
  
  <p>I get the java.nio.file.FileAlreadyExistsException because my folder (2014) already exists. What I actually want to do is move all the files that start with "2014" INSIDE the 2014 directory.</p>