antis

/**
* zip 导出
* @param response
* @param zipName
* @throws Exception
*/
private void outZip(HttpServletResponse response, String zipName) throws Exception {
// tempFilePath 为服务器上文件保存路径
String zipPathName = tempFilePath + File.separator + zipName;
BufferedOutputStream out = null;
InputStream in = null;
try {
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(zipName, "UTF-8"));
out = new BufferedOutputStream(response.getOutputStream());// 获取输出流
in = new BufferedInputStream(new FileInputStream(new File(zipPathName)));// 将文件读取
byte[] b = new byte[in.available()];
in.read(b);
out.write(b);
out.flush();
} catch (Exception e) {
throw e;
} finally {
try {
if (in != null)
in.close();
if (out != null)
out.close();
} catch (IOException e) {
throw e;
}
}

分类:

技术点:

相关文章:

  • 2022-02-07
  • 2021-10-01
猜你喜欢
  • 2021-11-23
  • 2022-12-23
  • 2021-12-03
  • 2021-10-06
  • 2021-11-11
  • 2018-12-14
相关资源
相似解决方案