我正在尝试借助此代码以编程方式在我的应用程序中解压缩.zip
,
public void unzip(String _zipFile, String _targetLocation) {
dirChecker(_targetLocation);
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_targetLocation + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
Log.i("xoxo", "unzip: completed!!!");
} catch (Exception e) {
Log.i("xoxo", "unzip: err: - " + e.toString());
}
}
一切都很好,但是问题是我遇到了错误,
java.util.zip.ZipException: only DEFLATED entries can have EXT descriptor
在尝试解压缩在Linux环境上运行的服务器创建的.zip
时。
如何解决此错误?
答案 0 :(得分:0)
您可以尝试此库 https://github.com/ankitdubey021/ExtractionLib
void extract(){
try {
File outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "value1.jar");
Extract.extract(outputFile, new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "extration").toString());
Toast.makeText(MainActivity.this, "Extracted!", Toast.LENGTH_SHORT).show();
}catch(Exception e){
System.out.println(e);
}}
它将轻松提取您的zip文件。 3年前,我在一个项目中使用了它。仍在工作。