IE 播放wav文件

来源:互联网 发布:程序员要懂软件架构吗 编辑:程序博客网 时间:2024/05/21 19:23

IE9下载wav文件总是播放的解决办法

最近写代码遇到问题,音频wav格式的文件总是下载不了,谷歌可以 。但IE浏览器总是直接打开,自己在网上找到方法解决后  在这里整理给大家。
以下是代码:
HTML :
window.open("DownloadFileLocal?data='"+StrData+"'","newwindow","height=30,width=40,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");
Java:
String downFilename=null;downFilename="abc.wav";try{     response.setContentType("application/octet-stream");              response.setHeader("Location",downFilename);     response.setHeader("Content-Disposition", "attachment; filename=" + downFilename);     response.setHeader("Connection", "Keep-Alive" );                       OutputStream outputStream = response.getOutputStream();     InputStream inputStream = new FileInputStream(filepath+downFilename);     byte[] buffer = new byte[1024];     int x = -1;     while ((x = inputStream.read(buffer)) != -1) {     outputStream.write(buffer, 0, x); } outputStream.flush(); outputStream.close();}catch(FileNotFoundException e1){System.out.println("没有找到您要的文件");}catch(Exception e){System.out.println("系统错误,请及时与管理员联系");}
注意:这是以流的方式下载的,也就是说只能下载一个文件,如果要实现多个文件下载,建议打包下载

希望能帮到大家!


0 0
原创粉丝点击