Extract Zip File With Adler32 Checksum In Java
Chapter:
ZIP
Last Updated:
23-04-2016 03:40:42 UTC
Program:
/* ............... START ............... */
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 JavaExtractFileWithAdler32 {
public static void main(String args[]) {
String sourceZipFile = "C:/File/File.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();
// crate OutputStream to extract the entry from zip file
OutputStream os = new FileOutputStream("c:/extract.txt");
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);
}
// close the streams
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);
}
}
}
/* ............... END ............... */
Tags
Extract Zip File With Adler32, Java