我想解压缩存储在原始文件夹中的zip文件。代码如下Android解压缩不是目录问题
try
{
File myDir = new File(getFilesDir().getAbsolutePath());
File newFile = new File(myDir + "/imageFolder");
if(!newFile.exists())
{
newFile.mkdir();
}
ZipInputStream zipIs = new ZipInputStream(con
.getResources().openRawResource(R.raw.images));
ZipEntry ze = null;
while ((ze = zipIs.getNextEntry()) != null)
{
Log.v("Name", ze.getName());
Log.v("Size", "" + ze.getSize());
if(ze.getSize() >0)
{
FileOutputStream fout = new FileOutputStream(newFile
+ "/" + ze.getName());
byte[] buffer = new byte[1024];
int length = 0;
while ((length = zipIs.read(buffer)) > 0)
{
fout.write(buffer, 0, length);
}
zipIs.closeEntry();
fout.close();
}
}
zipIs.close();
} catch (Exception e)
{
e.printStackTrace();
}
但我不断收到此错误
11月1日至18日:24:28.301:W/System.err的(2285):java.io.FileNotFoundException: /数据/data/com.example.ziptests/files/imageFolder/TestImages/background.png (不是一个目录)
我完全不知道为什么它是导致此,它找到的文件,但是当它涉及把它们写出来,它会引起这个错误。最初我发现了一个问题,这是由于在Mac上压缩zip文件引起的,所以我将文件压缩到了我的Windows机器上,而不是这样,这样摆脱了一个问题(当您在Mac上压缩时,它会添加这些额外的文件夹和文件这样的s store.ds导致尝试解压缩时出错),但这不是一个目录错误不断出现。
任何想法为什么会发生这种情况?
压缩文件使用winzip软件压缩? –
是的,我把它压缩在Windows上而不是在Mac上,因为它在mac上的压缩导致问题,因为它增加了额外的文件夹,这是烦人的 – AdamM
看到我的答案.... –