Thursday, 10 October 2013

Textual description of firstImageUrl

How to read zip file in java

java Program to unzip a zip file .
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class UnzipExample {

 public static void main(String[] args) throws IOException {

  String inputZipFilePath = "C:\\Downloads\\Office.zip";

  String outputFileDir = "C:\\Downloads\\Office";
  byte[] buffer = new byte[1024];

  File outputDir = new File(outputFileDir);

  if (!outputDir.exists())
   outputDir.mkdir();

  ZipInputStream zin = new ZipInputStream(new FileInputStream(new File(
    inputZipFilePath)));

  ZipEntry next = zin.getNextEntry();

  while (next != null) {
   String name = next.getName();
   File fileToWrite = new File(outputFileDir + File.separator + name);
   //create directory structure
   new File ( fileToWrite.getParent()).mkdirs();
   FileOutputStream fos = new FileOutputStream(fileToWrite);

   int len;
   while ((len = zin.read(buffer)) > 0) {
    fos.write(buffer, 0, len);
   }
   
    fos.close();   
             next = zin.getNextEntry();

  }
  zin.closeEntry();
     zin.close();
 
     System.out.println("Unzip File Completed");

 }

}


Post Comments And Suggestions !!