0
다음 압축 해제 기능이 모든 zip 파일에서 작동하지 않습니다. ZIP 파일은 하나 개의 XML 파일을 하나 개의 폴더 (이름 - "이미지")를 포함Android unzip 기능이 작동하지 않습니다.
- follows-로
내 zip 파일 패턴입니다.
- xml 파일의 이름은 zip 파일 이름과 동일합니다.
- 폴더 ("images")는 파일을 포함 할 수도 있고 포함하지 않을 수도 있습니다.
xml 파일을 zip 파일로 보내기 전에 유효성을 검사했습니다.
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;
}
'mkdirs()'는 성공하면 true를 반환하고 실패하면 false를 반환합니다. 이 값의 유효성을 검사하고 메소드가 실패한 이유를 이해하려고 시도하십시오. – AlexR
> 고맙습니다.하지만 부모님, 루프 처음에는 XML 파일 이름을 "파일 이름"변수로 설정합니다. 그런 다음 if 부분을 건너 뛰고 직접 "FileOutputStream fout = new FileOutputStream (path.substring (0, path.length() - 4) +"/ "+ filename);" 행과 예외를 throw합니다. – JohnC
이것은'ze'가 디렉토리가 아님을 의미합니다. – AlexR