title: java file.renameTo() does rename file but returns false. Why?
body: <p>The problem is that I need the file to move before the rest of my logic will work so when the method returns false I stop execution.</p>
  
  <p>However, when I check on the file in windows explorer it has a new name and it moved.</p>
  
  <p>Just curious why this is happening.</p>
  
  <p>here is some sample code I just tried to recreate the issue.  It's pretty much the same thing and it's working fine.</p>
  
  <pre><code>File testfile = new File("TestFile");
  
      if(!testfile.exists()){
  
          testfile.mkdirs();
  
      }
  
      File sample = new File("sample.txt");
  
      if(sample.exists()){
  
          boolean success = sample.renameTo(new File(testfile.getPath() + "\\" + sample.getName()));
  
          if(success){
  
              System.out.println("Moved");
  
          }
          else{
  
              System.out.println("Failed");
  
          }
  
      }
  </code></pre>
  
  <p>Edit: Solved it.  I'm sorry for wasting everyone's time with something so silly.  However, I really dont think I would have tracked this down if not for making this post.</p>
  
  <p>The solution was that I was actually looping through several files to move.  When the output said it failed then the program stopped and when I looked in explorer only the first of the files was actually moved so I assumed it was moving and then returning false.  However, the issue was that I was using the wrong variable as an index and so what was happeneing was that it did successfully move the file in index 0 and then when the loop repeated the index didnt increment so it tried to move index 0 again and therefore failed.</p>
  
  <p>Like I said, very stupid but thanks for bearing with me.</p>