Reading from a ZipInputStream into a ByteArrayOutputStream

后端 未结 10 1700
旧时难觅i
旧时难觅i 2021-02-05 08:14

I am trying to read a single file from a java.util.zip.ZipInputStream, and copy it into a java.io.ByteArrayOutputStream (so that I can then create a

10条回答
  •  花落未央
    2021-02-05 08:34

    t is unclear how you got the zipStream. It should work when you get it like this:

      zipStream = zipFile.getInputStream(zipEntry)
    

    If you are obtaining the ZipInputStream from a ZipFile you can get one stream for the 3d party library, let it use it, and you obtain another input stream using the code before.

    Remember, an inputstream is a cursor. If you have the entire data (like a ZipFile) you can ask for N cursors over it.

    A diferent case is if you only have an "GZip" inputstream, only an zipped byte stream. In that case you ByteArrayOutputStream buffer makes all sense.

提交回复
热议问题