我检查了java api文件,它说getNextEntry()读取下一个ZIP文件条目并将流定位在条目数据的开头.
它是什么意思"读取NEXT zip文件"?为什么"下一个"?
我有这段代码,这一行有 ze = zin.getNextEntry()什么意义?
public void unzip() {
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if(ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_location + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
}
Run Code Online (Sandbox Code Playgroud)
它读取zip文件中的下一个条目.
zip文件在逻辑上包含主要的其他文件 - 因此foo.zip可以包含文件a.txt和b.txt.getNextEntry()您将移动到存档中的下一个文件.
(我从来没有特别热衷于ZipInputStream使用继承建模的方式InputStream,但这是另一回事.)