最近项目后台需要给业务添加二维码图片并且要导出成包提供下载,希望这个方法能帮助到大家
注意代码中有写类没贴出来,大家看方法名称应该能猜出来
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();
}
}
以上内容来源于网络,由“WiFi之家网”整理收藏!
原创文章,作者:电脑教程,如若转载,请注明出处:https://www.224m.com/197845.html