当使用 Java 读入压缩文件时,如何通过管道将输入流传输到压缩文件?
我想要执行一个程序,并在它运行时读取它的输出并将输出输出到压缩文件中。 程序的输出可能非常大,因此我们的想法是不要在内存中保存太多内容 - 只是在我得到它时将其发送到 zip 中。
I'm wanting to execute a program and as it runs read in it's output and pipe out the output into a zipped file. The output of the program can be quite large so the idea is to not hold too much in memory - just to send it to the zip as I get it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
换句话说:
您创建一个
ZipEntry
,它构成该 zip 文件中的一个文件。即当你打开 myFile.zip 时,里面有 3 个文件,每个文件都是一个
ZipEntry
。您将
ZipEntry
放入您的ZipOutputStream
inputStream
读入字节缓冲区,并记住计数。count
不是-1
,但将该字节 byffer 写入您的zipStream
。完成后关闭流。 将其包装在您认为合适的方法中。
In otherwords:
ZipOutputStream
, giving it the file you want to write to.You create a
ZipEntry
, which constitutes a file within that zip file.i.e. When you open myFile.zip, and there are 3 files in there, each file is a
ZipEntry
.You put that
ZipEntry
into yourZipOutputStream
inputStream
into your byte buffer, and remember the count.count
is not-1
, write that byte byffer to yourzipStream
.Close out your streams when you are done. Wrap it in a method as you see fit.