I am trying to write a MIDI file on SDcard. It works on my device but not in the emulator. Here’s the error on the logCat :
12-25 09:18:27.733: W/ExternalStorage(1951): Error create /sdcard/download/test.mid
12-25 09:18:27.733: W/ExternalStorage(1951): java.io.FileNotFoundException: /sdcard/download/test.mid
12-25 09:18:27.733: W/ExternalStorage(1951): at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:244)
12-25 09:18:27.733: W/ExternalStorage(1951): at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
12-25 09:18:27.733: W/ExternalStorage(1951): at java.io.FileOutputStream.<init>(FileOutputStream.java:168)
12-25 09:18:27.733: W/ExternalStorage(1951): at java.io.FileOutputStream.<init>(FileOutputStream.java:147)
I have set the permission in the manifest file, and change the path from “/sdcard/download/test.mid” to Environment.getExternalStorageDirectory()+”/download/test.mid” but still doesn’t work.
FYI, I use Kevin Boone’s MidiFile class, and here’s my code :
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
mf.writeToFile(Environment.getExternalStorageDirectory()+"/download/test.mid");
}
Well first make sure you have the proper permission, if you don’t add this to you’re AndroidManifest.xml
Secondly you should also check if download folder exist if not you have to create it. Check the method exist from the File class.
If you take a look at Kevin’s MidiFile method use it only create a file on a specific path it does not ensure the path exist that is your job