This is the code I'm using to write a file .name
to some folders in path /sdcard/
that with name starts with cimage
. 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.
public static void WriteName(ArrayList<String> citem) {
final String not_writable = "norw";
for (int i = 0; i < 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)));
}
}
}
So what happens is that when the method tries to write the last 2 folders it throws an IOException
.
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
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?