码迷,mamicode.com
首页 > 其他好文 > 详细

将zip文件以流的形式输出到页面

时间:2017-06-21 16:03:56      阅读:544      评论:0      收藏:0      [点我收藏+]

标签:参数   cep   int   nes   text   try   输入流   tac   path   

//将文件以流的形式输出
//获取到zip文件的地址
String zipPath = businessMessageInter.downlodImgs(bussNo,imageIndexList,userLoginOut);
HttpServletResponse response = SessionUtil.getResponse();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
// 2.设置文件头:最后一个参数是设置下载文件名
response.setHeader("Content-Disposition", "attachment;fileName=" + zipPath+".zip");
File zipFile = new File(zipPath+".zip");
FileInputStream fis = null;
ServletOutputStream out = null;
try {
//获取输入流
fis = new FileInputStream(zipFile);
//获取输出流
out = response.getOutputStream();
int b = 0;
byte[] buffer = new byte[1024];
//遍历输入流到输出流
while ((b = fis.read(buffer)) != -1) {
// 4.写到输出流(out)中
out.write(buffer, 0, b);
}
fis.close();
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}

将zip文件以流的形式输出到页面

标签:参数   cep   int   nes   text   try   输入流   tac   path   

原文地址:http://www.cnblogs.com/onfly/p/7059853.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!