【发布时间】:2019-10-09 16:50:06
【问题描述】:
邮编结构:-
OuterZip.zip--|
|--Folder1---InnerZip.zip--|
|--TxtFile1.txt // Requirement is to read content of txt file
|--TxtFile2.txt // Without extracting any of zip file
现在我可以读取 txt 文件的名称,但不能读取其中的内容。
代码:-
public static void main(String arg[]){
ZipFile zip = new ZipFile("Outer.zip");
ZipEntry ze;
for (Enumeration e = zip.entries(); e.hasMoreElements();) {
ZipEntry entry = (ZipEntry) e.nextElement();
ZipInputStream zin = new ZipInputStream(zip.getInputStream(entry));
while ((ze = zin.getNextEntry()) != null)
{
System.out.println(ze.getName()); //Can read names of txtfiles, Not contents
zip.getInputStream(ze); // It is giving null
}
}
}
PS:- 1. 不想在文件系统中提取任何 zip 文件。
2. 已经在SOF上看到了一些答案。
【问题讨论】: