Java Android解压功能不工作
以下解压finction不适用于所有zip文件 我的zip文件模式如下-Java Android解压功能不工作,java,android,xml,zip,unzip,Java,Android,Xml,Zip,Unzip,以下解压finction不适用于所有zip文件 我的zip文件模式如下- Zip文件包含一个xml文件和一个文件夹(名称-“图像”) xml文件的名称与zip文件名相同 文件夹(“图像”)可能包含也可能不包含任何文件 在将xml文件放入zip文件之前,我已经验证了它 对于某些zip文件,它在这一行抛出异常- FileOutputStream fout = new ileOutputStream(path.substring(0,path.length()-4)+"/"+filename); 功
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;
}
这种方法效果很好。在Linux平台中创建ZIP时存在权限问题。但当我更改文件权限时,该函数开始正常工作
mkdirs()
如果成功则返回true,如果失败则返回false。验证此值并尝试理解该方法失败的原因。>谢谢,但在父while循环中,它首先将xml文件名设置为“filename”变量。然后它跳过if部分,直接转到“FileOutputStream fout=newfileoutputstream(path.substring(0,path.length()-4)+”/“+filename);”行并抛出异常。这意味着ze
不是目录。是的。首先获取文件名,然后是目录名.Fine。因此,只需调试代码并尝试了解问题所在。