如何从 ZipEntry 创建输入流
我有一个包装 ZipEntry 的类,但我正在努力了解如何编写一种从任何一个 ZipEntry 返回输入流的方法。我设法编写了一些可以返回 ZipFile 输入流数组的东西,但我需要一种方法来仅从一个 ZipEntry 获取输入流。
I have a class which wraps ZipEntrys, but I'm struggling to see how I could then write a method that returns an input stream from any one ZipEntry. I managed to write something that could return an array of input streams for a ZipFile, but I need a way to get an input stream from just one ZipEntry.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个怎么样?
How about this?
您是否没有 ZipEntry 来源的 ZipFile 实例?如果你这样做,你可以使用 ZipFile.getInputStream(ZipEntry)。
https://docs.oracle.com/javase /8/docs/api/java/util/zip/ZipFile.html
PS。快速浏览一下代码,您会发现 ZipEntry 并不是 zip 文件中基础数据的包装器。据我所知,它只是条目的“占位符”(即压缩文件属性而不是数据)。实际的流是通过 ZipFile 类中的 JNI 调用创建的。这意味着我不相信你能以实际的方式做你想做的事。
Do you not have the ZipFile instance from which the ZipEntry was sourced? If you do you could use ZipFile.getInputStream(ZipEntry).
https://docs.oracle.com/javase/8/docs/api/java/util/zip/ZipFile.html
PS. Just had a quick look at the code and a ZipEntry is not a wrapper for the underlying data in the zip file. It is just a "place holder" for the entry as far as I can see (i.e. zipped file attributes not the data). The actual stream is created through a JNI call in the ZipFile class. Meaning that I do not believe you can do what you are looking to do in a practical way.
在这里找到的:
从 ZipInputStream 获取 ZipEntry 的输入流(不使用 ZipFile 类) )
对从 zip 文件打开的输入流是什么的误解。
解决方案:从 zip 文件打开输入流
ZipInputStream
zipInputStream = ZipInputStream(new FileInputStream(zipfile)
,运行循环
zipInputStream.getNextEntry()
。对于每一轮,您都有当前条目的输入流(之前为 zip 文件打开);
..
It was found here:
getInputStream for a ZipEntry from ZipInputStream (without using the ZipFile class)
Misunderstanding in what is the input stream that is opened from zip file.
Solution: open input stream from zip file
ZipInputStream
zipInputStream = ZipInputStream(new FileInputStream(zipfile)
,run cycle
zipInputStream.getNextEntry()
.For every round you have the inputstream for current entry (opened for zip file before);
..