不知道名网友 2017-12-21 07:13 采纳率: 50%
浏览 1298
已结题

这个有时候读取文件为什么会断流? 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文件是可以正常播放完的

  • 写回答

6条回答 默认 最新

  • 小薇新视界 2017-12-21 07:28
    关注

    fis.read(buf)

    评论

报告相同问题?