title: android file.renameTo changes subdir names
body: <p>I'm having a very strange problem around renaming folders in android and then reading the file again. I could never reproduce this on any or our local test devices and no one I know had a good idea. </p>
  
  <h2>Open Question:</h2>
  
  <ul>
  <li>What can it be that changes the sub folder name when renaming a file with <code>renameTo()</code>? </li>
  <li>What are some limitations of the file system, combined with Char encoding that I'm missing here? (<em>I also didn't find anything where I can spec char encoding for the <code>File</code> class</em>)</li>
  </ul>
  
  <h2>Problem</h2>
  
  <p>I have a folder called <code>name/</code> with it's content being other files and folders. <code>name/</code> can be anything as it's user generated folder names. We have this working across many languages incl. Arabic, Chinese and more.
  This problem happens on multiple devices.</p>
  
  <p>I'm moving all the content from <code>name/</code> to <code>.old/name/</code>. The code I use is</p>
  
  <pre><code>File[] dirs = mRootDir.listFiles(FileFilters.FilterDotFiles); // name/ will be in that list
  mOldTmp.mkdir(); //create the .old folder
  for(File f : dirs) { //move all dirs into .old
      File oldSubDir = new File(mOldTmp, f.getName());
      boolean renameSuccess = f.renameTo(oldSubDir); //true, as I otherwise would never run into the problem later in code.
  }
  </code></pre>
  
  <p>The files get all moved. It seems that the folder names get messed up on some occasion. When I list the files from the <code>.old</code> folder later with :</p>
  
  <pre><code>for(File dir : mOldTmp.listFiles(FileFilters.FilterFiles)) {
      for(File f : dir.listFiles(FileFilters.FilterDotFiles)) {
      }
  }
  </code></pre>
  
  <p>I get files that have the following path. This particular one is an arabic user. When trying to read the file with creating a new <code>new InputSteam(new FileInputStream(f))</code> I get an <code>IOException</code>:</p>
  
  <pre><code>.old/ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃÂ¬ÃÂÃÂÃÂÃÂ¯ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ/1392446611086.mzvg2bn56i1rsqe4ko1_1280.jpeg
  open failed: ENOENT (No such file or directory)
  </code></pre>
  
  <p>The user is complaining that files are not visible anymore. This makes sense as I can't read them, but that also means that the file has been available before the rename started.</p>
  
  <h2>Trying to reproduce it</h2>
  
  <p><strong>Test1:</strong> When I <code>adb push</code> a <code>name/</code> folder with Arabic characters and run my code, the <code>renameTo()</code> file operations and everything works as expected.</p>
  
  <p><strong>Test 2:</strong> I can create a <code>name/</code> folder on my computer with the name <code>ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃÂ¬ÃÂÃÂÃÂÃÂ¯ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ</code>. This works fine on OSX 10.8.5. When I try to use <code>adb push</code> then I get the same error</p>
  
  <pre><code>$ adb push . /mnt/sdcard/debug
  push: ./.old/ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃÂ¬ÃÂÃÂÃÂÃÂ¯ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ/.thumbs/1398208681403.2013-12-24 15.11.43.jpg -&gt; /mnt/sdcard/debug/.old/ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃÂ¬ÃÂÃÂÃÂÃÂ¯ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ/.thumbs/1398208681403.2013-12-24 15.11.43.jpg
  failed to copy './.old/ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃÂ¬ÃÂÃÂÃÂÃÂ¯ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ/.thumbs/1398208681403.2013-12-24 15.11.43.jpg' to '/mnt/sdcard/debug/.old/ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃÂ¬ÃÂÃÂÃÂÃÂ¯ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ/.thumbs/1398208681403.2013-12-24 15.11.43.jpg': No such file or directory
  
  $ ls -l .old/
  total 0
  drwxr-xr-x  24 philipp  staff   816B Apr 25 11:54 Ã?Â?Ã?Â§Ã?Â?Ã?Â?Ã?Â?Ã?Â?Ã?Â?Ã?Â¬Ã?Â?Ã?Â?Ã?Â?Ã?Â¯ Ã?Â?Ã?Â§Ã?Â?Ã?Â?Ã?Â?Ã?Â£Ã?Â?Ã?Â³Ã?Â?Ã?Â§Ã?Â?Ã?Â³Ã?Â?Ã?Â
  </code></pre>
  
  <p>Showing the content of this dir does not work consistent:</p>
  
  <pre><code>$ ls -l .old/ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃÂ¬ÃÂÃÂÃÂÃÂ¯\ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ/
  total 69880
  -rw-r--r--  1 philipp  staff   571K Apr 22 17:13 1398208669809.2014-02-08 14.26.50.jpg
  -rw-r--r--  1 philipp  staff   2.2M Apr 22 17:13 1398208670282.2014-02-08 14.22.11.jpg
  -rw-r--r--  1 philipp  staff   2.1M Apr 22 17:13 1398208670990.2014-02-08 14.21.11.jpg
  ... more files
  </code></pre>
  
  <p><em>next run</em></p>
  
  <pre><code>$ ls -l .old/ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃaÂ¬ÃÂÃÂÃÂÃÂ¯\ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ/
  ls: .old/ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃaÂ¬ÃÂÃÂÃÂÃÂ¯ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ/: File name too long
  </code></pre>
  
  <p>When I  <code>cd</code> into <code>ÃÂÃÂ§ÃÂÃÂÃÂÃÂÃÂÃaÂ¬ÃÂÃÂÃÂÃÂ¯ ÃÂÃÂ§ÃÂÃÂÃÂÃÂ£ÃÂÃÂ³ÃÂÃÂ§ÃÂÃÂ³ÃÂÃÂ/</code> I can always list the entire content.</p>