gpt4 book ai didi

java - 里面有多个文件的 gzip 存档

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:12:10 24 4
gpt4 key购买 nike

我需要创建一个包含多个文件的 gzip 存档,如果 java.util.zip.GZIPOutputStream 类没有可用的 ArchiveEntry,我该如何做到这一点?

最佳答案

根据Wikipedia entrygzip 上:

Although its file format also allows for multiple such streams to be concatenated (zipped files are simply decompressed concatenated as if they were originally one file), gzip is normally used to compress just single files.

这就是 GZIPOutputStream 不支持 ArchiveEntry 的原因。

通常,多个文件使用 tar 压缩成一个文件,然后使用 gzip 压缩生成一个 .tar.gz 压缩包。

您可以使用 Apache Commons Compress implementation for tar 以这种方式创建一个 tar.gz :

file_out = new FileOutputStream (new File ("archive.tar.gz"));
buffer_out = new BufferedOutputStream (file_out);
gzip_out = new GzipCompressorOutputStream (buffer_out);
tar_out = new TarArchiveOutputStream (gzip_out);

// .. and then talk to 'tar_out' to write stuff

Here is a more thorough example压缩整个目录。

关于java - 里面有多个文件的 gzip 存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10653683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com