ZipInputStream check whether zip file valid before going to extract it

TienDung

New Member
How we check whether zip file corrupted or valid Zip file before going to extract itmy code`\[code\]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) {;} } }}\[/code\]`this work fine with valid zipfile, but invalid zipfile it doesen't throw any exception not produce anything, but i need to confirm the validity of zip file before going to unzip it
 
Top