下载文件能下载但是ioException 报 closed

[复制链接]
查看11 | 回复1 | 2021-1-27 06:42:16 | 显示全部楼层 |阅读模式
这是源码
Stringpath="D:\\java_team.zip";
Filefile=newFile(path);
longsize=file.length();
try{
/**为了解决中文名称乱码问题这里是设置文件下载后的名称*/
StringfileName=newString(file.getName().getBytes("UTF-8"),"iso-8859-1");
/**清空response*/
response.reset();
response.setHeader("Accept-Ranges","bytes");
/**设置文件下载形式*/
response.setHeader("Content-disposition",String.format("attachment;filename=\"%s\"",fileName));
/**浏览器压缩数据的长度*/
response.addHeader("Content-Length",String.valueOf(size));
FileInputStreamin=newFileInputStream(file);
BufferedOutputStreamoutputStream=newBufferedOutputStream(response.getOutputStream());
byte[]b=newbyte[1024];
inti=0;
while((i=in.read(b))>0){
outputStream.write(b,0,i);
}
outputStream.flush();
outputStream.close();
in.close();
}catch(IOExceptione){
e.printStackTrace();
}
这是前台代码
$('#btns').click(function(){
varselectedIds=$("#list2").jqGrid("getGridParam","selarrrow");//得到选中的多行。
varurl="${appName}/personalcredit/datadowmload/zipDownLoad.ajax";
varform=$(".cus-form");
form.attr("action",url);
varinput=$("")
input.attr("type","hidden")
input.attr("name","packet_files")
input.attr("value",selectedIds)
form.append(input);
form.submit();
});
分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:42:16 | 显示全部楼层
outputStream.close();这行去掉,这里的输出流由容器管理的,你别去维护
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行