I'm trying to create a file in the external storage (SD Card) of my phone.
File F = new File(Environment.getExternalStorageDirectory() + File.separator + "MyBrand" + File.separator + "MyApp" + File.separator + "MyFile.srl");
but this is creating it in the Internal Storage area. I checked in Windows Explorer. When debugging, the path of F
is "/mtn/sdcard/MyBrand/MyApp/MyFile.srl", which is wrong because in Windows Explorer the name of the sdcard is really "SD Card" (with a space). I also tried .getAbsolutePath
at the end of getExternalStorageDirectory()` but it did the exact same thing.
My code for creating this file:
if (F.exists() == false)
{
try
{
F.getParentFile().getParentFile().mkdir();
F.getParentFile().mkdir();
F.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
scr_save();
}
else
scr_load();
It does the mkdirs() and createNewFile() just fine, but scr_save and scr_load always throw exceptions, either FileNotFound or IOException.
EDIT: I've also been testing it when not plugged into my computer, just to make sure of no interference. To be safe, i always delete the paths and file before unplugging it. It seems to create the dirs and file, but then not reading it right (could it be not serialized properly? i use this file to store serialized objects).
EDIT: there was an error originally. I was putting in the path + filename as a single parameter to F. Now I pass the path and filename as 2 separate strings. However, i'm still experiencing the same problem :(
I have the correct permission in my manifest (.WRITE_EXTERNAL_STORAGE)
I use Windows 7 64-bit, and also the 64-bit version of Eclipse. My phone is a LG-MS770.
Anyway please help. No clue why the getExternalSorage is not working.