0

I am trying to read an audio file that I have previously saved on my external storage but it seems that I cannot find it with the methods that I am using.

This is what I use in order to save the file in the external sdcard;

outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ejemplo.3gpp";

And this is what I use in order to get back the byteArray of the audio file recorded:

InputStream is =this.openFileInput("/sdcard/ejemplo.3gpp"); 
bytes = IOUtils.toByteArray(is);

For some reason, it seems that when I call openFileInput is not able to find the file, but with "Root browser" I have checked that actually the file is placed in "/sdcard/ejemplo.3gpp" so I dont know what is going on .... Any suggestions?

paviflo
  • 105
  • 2
  • 13

1 Answers1

2

/sdcard/ is not default. It can be changed by OEM and in some devices it is sdcard0 So use the Environment class as you use it to save the file.

File file = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + "/ejemplo.3gpp");
InputStream is = new FileInputStream(file);
bytes = IOUtils.toByteArray(is);
Sunny
  • 14,522
  • 15
  • 84
  • 129
  • Now it seems that it finds the file, but for any reason the array that I got in return in just an array of 0`s ... but I can hear back the sound recorded and everything seems to be ok ... any idea about what is going on? – paviflo Apr 18 '14 at 12:16
  • Both permissions for write and read external storage are added – paviflo Apr 18 '14 at 12:22
  • Don't know why it is giving only zero. You can try some other methods to convert `inputstream` to `byte array`. http://stackoverflow.com/q/2436385/909317 – Sunny Apr 18 '14 at 12:35