这个有时候读取文件为什么会断流? while 到一半就断了

response.setHeader("Content-Type", "audio/mp3");

File file = new File(localhost_dir);
int len_l = (int) file.length();
byte[] buf = new byte[4096];
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);
}

这个有时候读取文件为什么会断流? while 到一半就断了
但是mp3文件是可以正常播放完的

阅读 1.9k
1 个回答

可能你需要 out.flush()

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题