java io流读取多个文件写进zip文件(zip文件夹可自定义,满足特定的需求)
代码如下
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("d:/opt/xbpm/upload/aa.zip");
Map<String, byte[]> datas = new HashMap<>();
datas.put("a/file1.pdf", FileUtil.readBytes("d:/opt/xbpm/upload/2021/1201/429476510253187073.pdf"));
ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(fos));
for (Map.Entry<String, byte[]> date : datas.entrySet()) {
zipOut.putNextEntry(new ZipEntry(date.getKey()));
zipOut.write(date.getValue());
}
zipOut.close();
}
需要实现一个对选择的工单附件进行导出(附件文件夹名按照“工单名称”或者“工单编号分类”),可是实际服务器存放的附件方式是:年月日+随机名称.pdf