java

How To Unzip Large File With Java

import java.io.*;
import java.util.zip.*;

public class UnZip {
   final static int BUFFER = 2048;
   
  // "/home/admin/Downloads/movies/stockv2@ingram.zip"
   public String unzipFile(String compressFilePath, String uncompressFolderPath){
	   
	   String uncompressedFilePath=null;
	   
	   try {
	         BufferedOutputStream dest = null;
	         FileInputStream fis = new   FileInputStream(compressFilePath);
	         ZipInputStream zis = new     ZipInputStream(new BufferedInputStream(fis));
	         ZipEntry entry;
	         while((entry = zis.getNextEntry()) != null) {
	        	 uncompressedFilePath=uncompressFolderPath+entry.getName();
	        	 System.out.println("Extracting: " +entry);
	            int count;
	            byte data[] = new byte[BUFFER];
	            // write the files to the disk
	            FileOutputStream fos = new 
		      FileOutputStream(uncompressedFilePath);
	            dest = new 
	              BufferedOutputStream(fos, BUFFER);
	            while ((count = zis.read(data, 0, BUFFER)) 
	              != -1) {
	               dest.write(data, 0, count);
	            }
	           
	            
	            dest.flush();
	            dest.close();
	         }
	         zis.close();
	      } catch(Exception e) {
	         e.printStackTrace();
	      }
	  
	   
	   
	   System.err.println(uncompressedFilePath);
	   
	   return uncompressedFilePath;
	   
   }
   
   
   public static void main (String argv[]) {
      
	   //String destinationPath="/home/admin/Downloads/movies/";
	   
	   
	   UnZip unZip = new UnZip();
	   System.out.println(unZip.unzipFile("/home/admin/Downloads/movies/stockv2@ingram.zip","/home/admin/Downloads/movies/"));	   
	   
   }	   
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s