Source Code : Unpack a segment from a zip

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Unpack a segment from a zip

   

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Utils {
  /**
   * unpack a segment from a zip
   * 
   * @param addsi
   * @param packetStream
   * @param version
   */
  public static void unpack(InputStream source, File destination) throws IOException {
    ZipInputStream zin = new ZipInputStream(source);
    ZipEntry zipEntry = null;
    FileOutputStream fout = null;

    byte[] buffer = new byte[4096];
    while ((zipEntry = zin.getNextEntry()) != null) {

      long ts = zipEntry.getTime();
      // the zip entry needs to be a full path from the
      // searchIndexDirectory... hence this is correct

      File f = new File(destination, zipEntry.getName());

      f.getParentFile().mkdirs();

      fout = new FileOutputStream(f);
      int len;
      while ((len = zin.read(buffer)) > 0) {
        fout.write(buffer, 0, len);
      }
      zin.closeEntry();
      fout.close();
      f.setLastModified(ts);
    }
    fout.close();
  }
}

   
    
    
  

Thank with us