title: Files.move and Files.copy is throwing java.nio.file.FileAlreadyExistsException
body: <p>I want to delete one file and rename another file with the old file but I am not able to move this file as java is throwing <code>java.nio.file.FileAlreadyExistsException</code> Following is the code snippet I am using </p>
  
  <pre><code>static void swapData(String origFilePath, String tempFilePath) throws IOException{
  
          Path tempPath = FileSystems.getDefault().getPath(tempFilePath);
          Path origPath = FileSystems.getDefault().getPath(origFilePath);
          try{
              String origFileName = null;
              File origFileRef = new File(origFilePath);
              if(Files.exists(origPath)){
                  origFileName = origFileRef.getName();
                  Files.delete(origPath);
                  if(Files.exists(origPath))
                      throw new IOException("cannot able to delete original file");
              }
              if(origFileName != null)
                  Files.move(tempPath, tempPath.resolveSibling(origFileName), StandardCopyOption.REPLACE_EXISTING);
          }catch(IOException e){
              throw e;
          }
      }
  </code></pre>
  
  <p>Here is the exception I am recieving <a href="https://i.stack.imgur.com/bFvbe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bFvbe.png" alt="enter image description here"></a>
  on <code>Files.move(tempPath, tempPath.resolveSibling(origFileName), StandardCopyOption.REPLACE_EXISTING);</code></p>
  
  <p>Also when I see this file in windows explorer, its thumbnail is present but cannot able to open it. I am not able to understand why it is happening and If I am using REPLACE_EXISTING, why it is throwing FileAlreadyExistsException exception.</p>
  
  <p>Also I edited the previous question as it is not clearly stated.</p>
  
  <p>Please help.</p>
  
  <p>Anuj</p>