wav 文件下载(weblogic tomcat 可用)

阅读更多
response.reset();
String fname = contact_id+".wav";
response.setHeader("content-disposition", "attachment;filename=" + fname); 
BufferedOutputStream bos = null;
BufferedInputStream  bis = null;
try {
url = "/ivr"+url;

System.out.println("filepath:"+url);
            bis = new BufferedInputStream(new FileInputStream(url));       
            bos = new BufferedOutputStream(response.getOutputStream());
           
            byte[] buff = new byte[2048];
            int bytesRead;

           
 
        while( (bytesRead = bis.read(buff)) > 0) {
                bos.write(buff,0,bytesRead);
                buff = new byte[2048];
            }
        } catch(final IOException e) {
        e.printStackTrace();
        } catch(Exception e) {
        e.printStackTrace();
        }finally {
            if (bis != null)
                bis.close();
            if (bos != null)
            {
                bos.flush();
                bos.close();
                bos=null;
            }
        }
        response.flushBuffer();

你可能感兴趣的:(文件下载)