Parsing an XML inside a zip in
I have a Zip that contains two files: an XML and a thumbnail. I would like to open the XML file and parse it WITHOUT having to extract on disk.
One of DocumentBuilder's parse method requires an InputStream. Is there a way to get the InputStream of the XML in the Zipped file? I kinda got lost. I'm pretty sure ZipInputStream or ZipFile has something to offer, but I can't figure it out :/
Thank you in advance!
我相信你正在寻找这样的东西:
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
}
}
java.util.zip中有一些输入流类,不确定它们是否有帮助,但看起来很有希望,特别是ZipInputStream。
链接地址: http://www.djcxy.com/p/51534.html上一篇: 好的设计:如何使用超类的领域
下一篇: 解析一个zip中的XML