java输出流实现文件下载

//导出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输出流实现文件下载

上一篇:C# 当前程序所有线程


下一篇:Pig Latin儿童黑话(java)