res = response.getOutputStream();
// 清空输出流
response.reset();
SimpleDateFormat sFormat = new SimpleDateFormat("yyyyMMddhhmmss");
String realFileName = "template" + sFormat.format(new Date());
// 设定输出文件头
response.setHeader("Content-disposition ",
"attachment; filename=" + URLEncoder.encode(realFileName, "utf-8") + ".zip ");
response.setContentType("application/zip");
// ZipOutputStream zos = new ZipOutputStream(res, StandardCharsets.UTF_8);
ZipOutputStream zos = new ZipOutputStream(res);
for (List<PracticeApplyTableData> dates : map.values()) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
exportApplyTable(yearM, dates, output);
byte[] buffer = output.toByteArray();
ZipEntry entry = new ZipEntry("test" + dates.get(0).getTeachName() + ".doc");
zos.putNextEntry(entry);
// zos.setEncoding("UTF-8");
zos.write(buffer);
}
zos.flush();
zos.close();
网友评论