码迷,mamicode.com
首页 > 编程语言 > 详细

java输出流实现文件下载

时间:2014-07-14 23:08:05      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:style   blog   java   color   文件   os   

//导出Excel
            try {
                HSSFWorkbook wb = carService.export(list);  //调用service方法~!
                response.setContentType("application/vnd.ms-excel");  
                response.setHeader("Content-disposition", "attachment;filename=carsList.xls");  
                OutputStream ouputStream = response.getOutputStream();  
                wb.write(ouputStream);  
                ouputStream.flush();  
                ouputStream.close(); 
            } catch (Exception e) {    
                logger.error("车辆信息导出excel错误:", e);
            }  
            return null;

//导出zip文件
//response.reset();  
                        response.setCharacterEncoding("utf-8");
                        response.setContentType("application/octet-stream;charset=UTF-8");
                        response.setHeader("Content-Disposition", "attachment; filename=\"" + zipName + "\"");   
                        InputStream is = new FileInputStream(zipFile);     //是文件而不是文件名。
                        FileCopyUtils.copy(is, response.getOutputStream());//将文件写到输出流中
                        return null;

 

java输出流实现文件下载,布布扣,bubuko.com

java输出流实现文件下载

标签:style   blog   java   color   文件   os   

原文地址:http://www.cnblogs.com/simpledev/p/3842349.html

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