把多个file文件导出zip(怎样快速将多个文件夹里的文件导出来)

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

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

把多个file文件导出zip(怎样快速将多个文件夹里的文件导出来)

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

(0)
电脑教程电脑教程
上一篇 2022年12月26日
下一篇 2022年12月26日

相关推荐