Apache Common Compress 实现zip文件分卷压缩代码示例
时间: 2023-03-03 20:42:28 浏览: 429
zip压缩、解压代码示例
5星 · 资源好评率100%
答:Apache Commons Compress提供了一种实现zip文件分卷压缩的API,具体代码示例如下: try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(new FileOutputStream(zipFileName))) {
ArchiveEntry entry;
int bytesRead;
byte[] buffer = new byte[2048];
for (int i=0; i<files.length; i++) {
entry = zos.createArchiveEntry(files[i], files[i].getName());
zos.putArchiveEntry(entry);
try (FileInputStream fis = new FileInputStream(files[i])) {
while ((bytesRead = fis.read(buffer)) != -1) {
zos.write(buffer, 0, bytesRead);
}
}
zos.closeArchiveEntry();
}
}
阅读全文