【发布时间】:2011-05-29 02:31:32
【问题描述】:
在 android 上解压缩文件似乎非常慢。起初我以为这只是模拟器,但在手机上似乎是一样的。我尝试了不同的压缩级别,最终下降到存储模式,但仍然需要很长时间。
总之,一定是有原因的!还有其他人有这个问题吗?我的解压方法是这样的:
public void unzip()
{
try{
FileInputStream fin = new FileInputStream(zipFile);
ZipInputStream zin = new ZipInputStream(fin);
File rootfolder = new File(directory);
rootfolder.mkdirs();
ZipEntry ze = null;
while ((ze = zin.getNextEntry())!=null){
if(ze.isDirectory()){
dirChecker(ze.getName());
}
else{
FileOutputStream fout = new FileOutputStream(directory+ze.getName());
for(int c = zin.read();c!=-1;c=zin.read()){
fout.write(c);
}
//Debug.out("Closing streams");
zin.closeEntry();
fout.close();
}
}
zin.close();
}
catch(Exception e){
//Debug.out("Error trying to unzip file " + zipFile);
}
}
【问题讨论】:
-
考虑解压的位置。 Context.getCacheDir() 将是内部存储,其中 Environment.getDataDirectory() 可能是内部的(或不是),而 Environment.getExternalDirectory() 将在 SD 卡上。内存几乎肯定会更快。
标签: java android android-emulator unzip zipinputstream