title: Java File.renameTo(File) not working
body: <p>I'm trying to list a directory's contents, and rename certain files.</p>
  
  <pre><code>public void run(String dirName) {
      try {
          File parDir = new File(dirName);
          File[] dirContents = parDir.listFiles();
  
          // Rename if necessary
          for(File f : dirContents) {
              System.out.println("f is:\n" + f.toString());
              String name = f.getName();
              String subbedName = name.replaceAll("\uFFFD", "_");
  
              System.out.println("\n" + "name = " + name + ", subbedName = " + subbedName + "\n");
  
              if(!name.equals(subbedName)) {
                  File newFile = new File(f.getParentFile(), subbedName);
                  System.out.println("newFile is:\n" + newFile.toString());
                  if(!f.renameTo(newFile))
                      System.out.println("Tried to change file name but couldn't.");
              }
          }
      }
      catch(Exception exc1) {
          System.out.println("Something happened while listing and renaming directory contents: " + exc1.getMessage());
      }
  }
  </code></pre>
  
  <p>When I run this, I get "<code>Tried to change file name but couldn't.</code>" I don't <em>believe</em> that Java is considering these files to be "open", so I don't think that's the reason. I've even ran <code>chmod 777 myDir</code> where <code>myDir</code> is the value of the <code>dirName</code> string passed into the <code>run</code> method.</p>
  
  <p>What am I missing here? Why won't Java rename these file(s)? These are CentOS machines.</p>
  
  <p><strong>Edit</strong>: Added printouts for both <code>f</code> and <code>newFile</code>, which is as follows:</p>
  
  <pre><code>f is:
  /root/path/to/mydir/testï¿½.txt
  
  newFile is:
  /root/path/to/mydir/test_.txt
  </code></pre>