我正在尝试在zip文件中查找一个文件,并将其作为InputStream
获取。目前我所做的是这样的,但我不确定是否正确。
这是一个示例,原始内容稍长,但这是主要组成部分...
public InputStream Search_Image(String file_located, ZipInputStream zip)
throws IOException {
for (ZipEntry zip_e = zip.getNextEntry(); zip_e != null ; zip_e = zip.getNextEntry()) {
if (file_located.equals(zip_e.getName())) {
return zip;
}
if (zip_e.isDirectory()) {
Search_Image(file_located, zip);
}
}
return null;
}
我现在面临的主要问题是,Search_Image
中的 ZipInputStream
与原始组件的 ZipInputStream
相同...
if(zip_e.isDirectory()) {
//"zip" is the same as the original I need a change here to find folders again.
Search_Image(file_located, zip);
}
现在的问题是,如何将
ZipInputStream
作为新的zip_entry
获取?如果我的方法有任何问题,请纠正,因为我对这个类的逻辑仍然不太清楚。
equals(..)
而不是endsWith(..)
,请看一下我的第三点。 - Jack