I have mounted an external sd card (7.9GB). Following is the code I am using to transfer a raw audio file from my project to the sdcard. I am using JellyBean 4.2 version. I am able to achieve this using a fileManager app. So the sdcard definitely is writable.
File storagedir = new File("/mnt/extsd");
if (storagedir.isDirectory()) {
String[] dirlist = storagedir.list();
for (int i = 0; i < dirlist.length; i++) {
System.out.println(dirlist[i]);
}
File file = new File(storagedir, "Audio.mp3");
try {
InputStream is = getResources().openRawResource(R.raw.audio);
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read(data);
os.write(data);
is.close();
os.close();
Toast.makeText(getApplicationContext(), "Saved!", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
Manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
But I get the File not found exception:
java.io.FileNotFoundException: mnt/extsd/Audio.mp3 openfailed:
EACCES (Permission Denied)