最近项目后台需要给业务添加二维码图片并且要导出成包提供下载,希望这个方法能帮助到大家

注意代码中有写类没贴出来,大家看方法名称应该能猜出来

public void exportZipFile (List fileList, String zipName) {

// File target = new File(StorageTypes.IMAGE.getPath()+”/”+zipName);

File target = new File(StorageTypes.ROOT.getPath()+”/”+zipName);

try (ArchiveOutputStream o = new ZipArchiveOutputStream(target)) {

for (File f : fileList) {

ArchiveEntry entry = o.createArchiveEntry(f, f.getName());

o.putArchiveEntry(entry);

if (f.isFile()) {

try (InputStream i = Files.newInputStream(f.toPath())) {

IOUtils.copy(i, o);

}

}

o.closeArchiveEntry();

}

} catch (IOException e) {

e.printStackTrace();

}

}