우리가 확인하는 방법 zip 파일 손상되거나 유효 Zip 파일 내 code` 그것을확인 ZipInputStream 여부를 zip 파일 유효 그것을 추출 가기 전에
를 추출하는
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public void unzip() {
FileInputStream fin = null;
ZipInputStream zin = null;
OutputStream fout = null;
File outputDir = new File(_location);
File tmp = null;
try {
fin = new FileInputStream(_zipFile);
zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.d("Decompress", "Unzipping " + ze.getName());
if (ze.isDirectory()) {
dirChecker(ze.getName());
} else {
tmp = File.createTempFile("decomp", ".tmp", outputDir);
fout = new BufferedOutputStream(new FileOutputStream(tmp));
DownloadFile.copyStream(zin, fout, _buffer, BUFFER_SIZE);
zin.closeEntry();
fout.close();
fout = null;
tmp.renameTo(new File(_location + ze.getName()));
tmp = null;
}
}
zin.close();
zin = null;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tmp != null ) { try { tmp.delete(); } catch (Exception ignore) {;} }
if (fout != null) { try { fout.close(); } catch (Exception ignore) {;} }
if (zin != null ) { try { zin.closeEntry(); } catch (Exception ignore) {;} }
if (fin != null ) { try { fin.close(); } catch (Exception ignore) {;} }
}
}
`
이 가기 전에 여부 유효한 zipfile로 잘 작동하지만 아무 것도 생성하지 않는 예외는 throw하지 않습니다. 그러나 압축을 풀기 전에 zip 파일의 유효성을 확인해야합니다.