java 包含多个文件的 gzip 存档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10653683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gzip archive with multiple files inside
提问by ira_ira
I need to create a gzip archive with multiple files inside, how can I do this without ArchiveEntry
available for java.util.zip.GZIPOutputStream
class?
我需要创建一个包含多个文件的 gzip 存档,如果没有ArchiveEntry
可用的java.util.zip.GZIPOutputStream
课程,我怎么能做到这一点?
回答by ArjunShankar
According to the Wikipedia entryon gzip
:
按照维基百科条目上gzip
:
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.
尽管它的文件格式也允许连接多个这样的流(压缩文件只是简单地解压缩连接,就好像它们最初是一个文件一样),但 gzip 通常只用于压缩单个文件。
This is why GZIPOutputStream
doesn't support ArchiveEntry
.
这就是为什么GZIPOutputStream
不支持ArchiveEntry
.
Normally, multiple files are archived into one with tar
, then compressed with gzip
to produce a .tar.gz
compressed archive.
通常,多个文件用 存档为一个tar
,然后用 压缩gzip
以生成.tar.gz
压缩存档。
You could create a tar.gz
in this way by using the Apache Commons Compress
implementation for tar
:
您可以tar.gz
通过使用以下Apache Commons Compress
实现以tar
这种方式创建一个:
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 examplethat compresses entire directories.
回答by ControlAltDel
GZip compresses a stream. Typically, when people use GZip with multiple files, they also use tar to munch them together
GZip 压缩流。通常,当人们将 GZip 与多个文件一起使用时,他们也会使用 tar 将它们一起咀嚼
You can find a java tar libarary here: http://www.trustice.com/java/tar/
你可以在这里找到一个 java tar 库:http: //www.trustice.com/java/tar/
Or you could use Zip instead of GZip
或者你可以使用 Zip 而不是 GZip