ace412146460
梧桐初恋
2017-12-21 11:47

Java为什么循环读取wav文件流,只能读取到第一个?

5
  • java
    response.setHeader("Content-Type", "audio/mpeg");
    byte[] buf = new byte[2048];
    int len_l;
    while (iter.hasNext()) {
        Object[] obj = iter.next();
        if (obj[0] instanceof File) {
            for (int i = 0; i < obj.length; i++) {
                File file = (File) obj[i];

                File fileWav = new File(dir+file.getName());

                FileInputStream fis = new FileInputStream(fileWav);

                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();

// System.out.println(file.getName() + " ");
//
// listArr.add(file.getName());

            }
        }
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

7条回答