Mysterious IOException while writing a file
<p>This is the code I'm using to write a file <code>.name</code> to some folders in path <code>/sdcard/</code> that with name starts with <code>cimage</code>. Currently I have 4 such folders, 2 of them were created lately. The problem is with these two and affects any folder that I manually add later.</p>

<pre><code>public static void WriteName(ArrayList&lt;String&gt; citem) {
    final String not_writable = "norw";
    for (int i = 0; i &lt; citem.size(); i++) {
        try {
            File root = new File(Environment.getExternalStorageDirectory()
                    .getName() + "/" + citem.get(i));
            File namefile = new File(root, ".name");
            FileReader namereader = new FileReader(namefile);
            BufferedReader in = new BufferedReader(namereader);
            String[] str_array = new String[4];
            str_array[0] = in.readLine();
            str_array[1] = in.readLine();
            str_array[2] = in.readLine();
            str_array[3] = in.readLine();
            Log.d("NameWrite", "line 4: " + str_array[3]);
            if (str_array[3] == null || !str_array[3].equals(not_writable)) {
                FileWriter namewriter = new FileWriter(namefile);
                BufferedWriter out = new BufferedWriter(namewriter);
                out.write(i
                        + "\nCImage_"
                        + (i)
                        + "\nAutogenerated Stub\nnorw\n");
                out.close();
            } else {
                Log.d("NameManager.WriteName", "Skipping " + root
                        + ", norw set");
            }
        } catch (IOException e) {
            Log.e("NameManager.java : ", ("Error!! Not Writable!!"
                    + Environment.getExternalStorageDirectory().getName()
                    + "/" + citem.get(i)));
        }
    }

}
</code></pre>

<p>So what happens is that when the method tries to write the last 2 folders it throws an <code>IOException</code>.</p>

<pre><code>02-26 05:42:39.663: D/NameManager.java(5316): Checking for whatever
02-26 05:42:39.671: D/NameManager.java(5316): SDcard mounted RW
02-26 05:42:40.694: D/java.lang.java.lang.String(5316): file (43) :cimages
02-26 05:42:40.694: D/java.lang.java.lang.String(5316): file (76) :cimages_1
02-26 05:42:40.694: D/java.lang.java.lang.String(5316): file (77) :cimageslkj
02-26 05:42:40.694: D/java.lang.java.lang.String(5316): file (81) :cimages_2
02-26 05:42:40.694: D/NameWrite(5316): line 4: norw
02-26 05:42:40.694: D/NameManager.WriteName(5316): Skipping sdcard/cimages, norw set
02-26 05:42:40.702: D/NameWrite(5316): line 4: norw
02-26 05:42:40.702: D/NameManager.WriteName(5316): Skipping sdcard/cimages_1, norw set
02-26 05:42:40.702: E/NameManager.java :(5316): Error!! Not Writable!!sdcard/cimageslkj
02-26 05:42:40.710: E/NameManager.java :(5316): Error!! Not Writable!!sdcard/cimages_2
02-26 05:42:40.725: D/java.lang.java.lang.String(5316): file (77) :cimageslkj
</code></pre>

<p>I can find no explanation for this behavior. All other apps can write to those folder in case you are wondering. What might be causing this?</p>
