使用Common compress 解压Zip文件, 可以指定字符编码,如下代码片段,
public static boolean unZip(String zipFileString, String outPathString,File files[] )throws Exception {
// android.util.Log.v(TAG, "unZip(String, String)");// long first=System.currentTimeMillis();
String szName = "";
int i=0;
int len;
byte[] buffer = new byte[4096];
ZipFile zipFile = new ZipFile(zipFileString,"GBK");
InputStream inZip;
String dir=outPathString;
if(!new File(dir).exists())
new File(dir).mkdir();
for (Enumeration<ZipArchiveEntry> e = zipFile.getEntries(); e.hasMoreElements();) {
ZipArchiveEntry entry = e.nextElement();
szName=entry.getName();
inZip=zipFile.getInputStream(entry);
if(szName.indexOf("/")>0){
String s=szName.substring(0,szName.indexOf("/"));
if(!new File(dir+"/"+s).exists())
new File(dir+"/"+s).mkdir();
}
if(!entry.isDirectory()) {
java.io.File file = new java.io.File(dir+java.io.File.separator+ szName);
file.createNewFile();
OutputStream out = new java.io.FileOutputStream(file);
while ((len = inZip.read(buffer)) != -1) {
out.write(buffer, 0, len);
out.flush();
}
out.close();
if(szName.matches(Constants.ZIP_FILE_FILTER_PARTERN)&&i<files.length)
files[i++]=file;
} else {
if(!szName.endsWith(".db")){
java.io.File folder = new java.io.File(dir+java.io.File.separator+ szName );
Debug.e(TAG, "folder path="+folder.getAbsolutePath());
folder.mkdirs();
}
}
inZip.close();
}
zipFile.close();
return true;
}