我正在尝试使用ZipInputStream将归档中的每个文件放入一个ArrayList中。我能用ZipInputStream做到这一点吗?
我的主要目标是解压cbr/cbz文件(档案中只包含图像(jpg/png)),我试图将这些图像中的每一个都放在ArrayList上,这样ZipInputStream to ArrayList是我最终将它们转换成位图的计划,但如果你能从ZipInputStream直接把它们转换成位图就太好了!
发布于 2012-03-23 08:02:40
最后,做我最初计划的事情占用了太多的内存!取而代之的是,我最终一次只取了一个ZipEntry,但只要是我想要的,它就不必每次都遍历每一个。
public Bitmap getBitmapFromZip(final String zipFilePath, final String imageFileInZip){
Bitmap result = null;
try {
ZipEntry ze = zipfile.getEntry(imageFileInZip);
InputStream in = zipfile.getInputStream(ze);
result = BitmapFactory.decodeStream(in);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;}
只需快速遍历开头即可获得所有名称
public ArrayList<String> unzip() {
ArrayList<String> fnames = ArrayList<String>();
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
if(ze.isDirectory()) {
} else {
fnames.add(ze.getName()/*fname[fname.length - 1]*/);
zin.closeEntry();
}
}
zin.close();
} catch(Exception e) {
}
return fnames;
} https://stackoverflow.com/questions/9774096
复制相似问题