//将文件以流的形式输出//获取到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();}
时间: 2024-10-13 16:47:29