Extract Zip File With Adler32 Checksum - Java File Path IO

Java examples for File Path IO:Zip File

Description

Extract Zip File With Adler32 Checksum

Demo Code

 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.Adler32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
 
public class Main {
 
        public static void main(String args[])
        {/*w w w . j a v  a  2 s. c  o  m*/
               
                String sourceZipFile = "C:/Folder/sourceFile.zip";
               
                try
                {
                        //create FileInputStream from the source zip file
                        FileInputStream fin = new FileInputStream(sourceZipFile);
                       
                        CheckedInputStream checksum = new CheckedInputStream(fin,new Adler32());
                         
                        ZipInputStream zin = new ZipInputStream(checksum);
                       
                        ZipEntry entry = zin.getNextEntry();
                       
                        OutputStream os = new FileOutputStream("c:/extractedFile.css");
                        byte[] buffer = new byte[1024];
                        int length;
                       
                        //read the entry from zip file and extract it to disk
                        while( (length = zin.read(buffer)) > 0)
                        {
                                os.write(buffer, 0, length);
                        }
                        os.close();
                        zin.close();
                     
                        System.out.println("File Extracted from zip file");
                       
                        System.out.println("Adler32 checksum is: " + checksum.getChecksum().getValue());
                         
                }
                catch(IOException e)
                {
                        System.out.println("IOException :" + e);
                }
               
        }
 
}

Result


Related Tutorials