你可以从这个source提取使用此代码zip文件:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import android.util.Log;
public class UnzipUtil
{
private String zipFile;
private String location;
public UnzipUtil(String zipFile, String location)
{
this.zipFile = zipFile;
this.location = location;
dirChecker("");
}
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());
byte[] buffer = new byte[8192];
int len;
while ((len = zin.read(buffer)) != -1)
{
fout.write(buffer, 0, len);
}
fout.close();
zin.closeEntry();
}
}
zin.close();
}
catch(Exception e)
{
Log.e("Decompress", "unzip", e);
}
}
private void dirChecker(String dir)
{
File f = new File(location + dir);
if(!f.isDirectory())
{
f.mkdirs();
}
}
}
给写入外部存储权限在AndroidManifest.xml
http://stackoverflow.com/questions/7485114/如何对拉链和解压最文件。检查它是否有帮助 – Raghunandan
看起来像一个坏主意。你为什么要把东西保存为zip,最终你的应用程序可能会占用比所需空间多一倍的空间。 –
其实我会在解压缩后删除这个zip文件。我不希望用户下载解压缩的大数据到Android设备。 – Master