我的代码有问题,我想将mp4音频文件转换为字节数组。 例如,我有2个不同歌曲的音频文件但长度相同,但是当我打印字节数组时,结果显示总是相似的,这是我的代码:
try {
FileInputStream fin = null;
fin = new FileInputStream("/mnt/sdcard/audiorecorder/tes.mp4");
BufferedInputStream bis = new BufferedInputStream(fin);
DataInputStream dis = new DataInputStream(bis);
byte fileContent[] = toByteArray(dis) ;
Log.d("tes", Arrays.toString(fileContent));
}
catch (Exception e){}
}
public static byte[] toByteArray(InputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
copy(in,out);
return out.toByteArray();
}
private static long copy(InputStream from, OutputStream to) throws IOException {
// TODO Auto-generated method stub
byte[] buf = new byte[4000];
long total = 0;
while (true){
int r = from.read(buf);
if (r==-1) break;
to.write(buf,0,r);
total += r;
}
return total;
}