当前位置: 代码迷 >> Android >> 保存在SD卡上的音频文件如何以byte[]形式读取
  详细解决方案

保存在SD卡上的音频文件如何以byte[]形式读取

热度:15   发布时间:2016-04-28 03:32:13.0
保存在SD卡上的音频文件怎么以byte[]形式读取?

我没有对byte[]进行任何操作,只是读取后保存,但是保存后文件就不能播放了,我的代码:
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard, "recording.3gpp");
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(file);
byte[] b = new byte[(int) file.length()];
fis.read(b);
fos = new FileOutputStream(file);
fos.write(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
    fis.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}

求指教!!
多谢了!
------解决思路----------------------
检查路径和文件名是否正确
------解决思路----------------------
不能播放多半是因为系统没找到,你那样做是有问题的,你仔细看看 File file = new File(sdCard, "recording.3gpp");这个重载方法的用法。
下面2句应该可以解决你的问题。
     String sdCard = Environment.getExternalStorageDirectory().getPath();
     File file = new File(sdCard + "/MUSIC/recording.3gpp");
简写:
     File file = new File(Environment.getExternalStorageDirectory().getPath()+ "/MUSIC/recording.3gpp");
------解决思路----------------------
byte[] b = new byte[(int) file.length()];
这里应改成byte[] b = new byte[(long) file.length()];
int类型不一定放得下文件总字节长度。
  相关解决方案