response.setHeader("Content-Type", "audio/mp3");
File file = new File(localhost_dir);
int len_l = (int) file.length();
byte[] buf = new byte[2048];
FileInputStream fis = new FileInputStream(file);
OutputStream out = response.getOutputStream();
len_l = fis.read(buf);
while (len_l != -1) {
out.write(buf, 0, len_l);
len_l = fis.read(buf);
}
out.flush();
out.close();
fis.close();
这段代码 ,会再浏览器生成一个mp3的流 ,我试过捕获错误,结果输出都是正常的
然后 我用
http://127.0.0.1/1.mp3
![图片说明](https://img-ask.csdn.net/upload/201712/21/1513847771_169841.png)
问题来了,这个mp3只能播放一小部分,下载下来用播放器播放是可以播放的,
其他都是正常的播放下来,他们都是上面的代码生成的mp3流?
生成的mp3有一个 耀 字 , 在网页流,就读不下去了(下载下来用播放器播放是可以播放的)