is it possible to get a zipentry's inputstream from a zipinputstream?

前端 未结 3 810
孤城傲影
孤城傲影 2020-12-10 23:39

I\'m receiving a ZipInputStream from another source, and I need to provide the first entry\'s InputStream to another source.

I was hoping to be able to do this witho

3条回答
  •  甜味超标
    2020-12-11 00:36

    In addition to @pstanton post here is an example of code. I solved the problem using the following code. It was difficult to understand what the previous answer without an example.

    //If you just want the first file in the zipped InputStream use this code. 
    //Otherwise loop through the InputStream using getNextEntry()
    //till you find the file you want.
    private InputStream convertToInputStream(InputStream stream) throws IOException {
        ZipInputStream zis = new ZipInputStream(stream);
        zis.getNextEntry();
        return zis;
    } 
    

    Using this code you can return an InputStream of the file that is zipped.

提交回复
热议问题