如何为zipinputstream的每个条目获得多个输入流,以稍后从这些输入流读取?
当我们创建zipinputstream
z
时,我们在其上调用getNextentry
,然后从z
读取,以获取下一个文件的内容。但是,我需要获取zipinputStream
s以供这些文件从它们中读取。我该怎么做?只需创建n
zipinputStreams
,然后在第一个1次,在第二个1次上调用getNextentry
,在nth上,...一次?有比这更优雅的方法吗?
我不能只将每个条目读为一个字节数组,因为当文件很大并且此类文件的最大大小只能是2个gig时,它会消耗太多RAM(我们不能创建byte []
数组比Java中的数组大),但是我有更大的文件。
When we create a ZipInputStream
z
, we call getNextEntry
on it and then read from z
, in order to get the contents of the next file. I, however, need to get ZipInputStream
s for those files to read from them later. How do I do that? Just create n
ZipInputStreams
, and call getNextEntry
on the first one 1 time, on the second one 2 times, ..., on the nth one n times? Is there a more elegant way to do that than this?
I can't just read each entry into an array of bytes, because that will consume too much RAM, when the files are large and the max size of such a file can only be 2 gigs (we can't create byte[]
arrays larger than that in Java), but I have larger files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
写这本书(不过是在Scala中,因为我使用Scala,而不是Java。
我实际上在此处从这里找到了这种方法:读取zip文件中的文件中的内容
Wrote this (it's in scala though, because I use scala, not Java.
I actually found this approach in the top answer from here: Read Content from Files which are inside Zip file