以下解压缩功能并不适用于所有zip文件。
我的压缩文件模式如下-
在将xml文件放入zip文件之前,我已经对其进行了验证。
它在这一行抛出一些压缩文件的异常-
FileOutputStream fout = new ileOutputStream(path.substring(0,path.length()-4)+"/"+filename);其职能是:
public boolean unZip(String path)
{
InputStream is;
ZipInputStream zis;
try
{
String filename;
is = new FileInputStream(path);
zis = new ZipInputStream(new BufferedInputStream(is));
ZipEntry ze;
byte[] buffer = new byte[1024];
int count;
while ((ze = zis.getNextEntry()) != null)
{
filename = ze.getName();
if (ze.isDirectory()) {
File fmd = new File(path.substring(0,path.length()-4)+"/"+filename);
fmd.mkdirs();
continue;
}
FileOutputStream fout = new FileOutputStream(path.substring(0,path.length()-4)+"/"+filename);
while ((count = zis.read(buffer)) != -1)
{
fout.write(buffer, 0, count);
}
fout.close();
zis.closeEntry();
}
zis.close();
}
catch(IOException e)
{
e.printStackTrace();
return false;
}
return true;
}

发布于 2014-06-24 04:26:53
这种方法效果很好。在Linux平台中创建zip时,这是一个权限问题。但是,当我更改文件权限时,函数开始正常工作。
https://stackoverflow.com/questions/24360476
复制相似问题