Java – parsing XML in zip memory

I have a zip that contains two files: XML and thumbnails I want to open the XML file and parse it without having to extract it on disk

A parsing method of documentbuilder requires an InputStream Is there any way to get the InputStream of XML in the zipped file? I'm a little lost I'm pretty sure what zipinputstream or zipfile can provide, but I can't figure out:/

Thank you first!

Solution

I believe you are looking for something like this:

FileInputStream fin = new FileInputStream("your.zip");
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
    if (ze.getName().equals("your.xml")) {
        // pass zin to DocumentBuilder
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>