title: Java.nio.Files.move is throwing exception when moving files multiple times
body: <p>I have a scenario in which stress testing is opening, moving and closing a file in loop multiple times. Here is the sample snippet:</p>
  
  <pre><code>String path = "TestFile.txt";
  for (int i = 0; i &lt; 10000; ++i) {
      System.out.println("opening file " + i + " times");
      RandomAccessFile file = new RandomAccessFile(path, "rw");
      File f = new File("temp.txt");
      if (f.exists())
          f.delete();
  
      boolean retValue = f.createNewFile();
      if (retValue) {
          file.close();
          Files.move(Paths.get("temp.txt"),Paths.get(path),
                  StandardCopyOption.REPLACE_EXISTING);
      } else {
          System.out.println("Error reporting");
      }
  }
  </code></pre>
  
  <p>When I try to run this code it is throwing exception after running 300~400 times.</p>
  
  <blockquote>
    <p><em>Exception in thread "main" java.nio.file.FileAlreadyExistsException: C:\Users\angupt\Desktop\temp.txt ->
    C:\Users\kellogs\Desktop\TestFile.txt     at
    sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:81)
      at
    sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
      at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:387)    at
    sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
      at java.nio.file.Files.move(Files.java:1395)    at
    temp.mainClass.main(mainClass.java:37)</em></p>
  </blockquote>
  
  <p>I guess this exception is occurring because file is opening, moving and closing very fast, but I don't know how to properly handle this scenario. Thread.sleep also not working. Please help me out to find why this is happening and how can I get rid of this situation.</p>