In this example we are going to see how to Create Zip File With Adler32 Checksum In Java.
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.Adler32; import java.util.zip.CheckedOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class JavaCreateZipFileWithAdler32 { public static void main(String args[]) { String zipFilePath = "C:/File/ZipFileExample.zip"; String filePath = "C:/File/File1.doc"; byte[] buffer = new byte[1024]; try { FileOutputStream fout = new FileOutputStream(zipFilePath); CheckedOutputStream checksum = new CheckedOutputStream(fout, new Adler32()); ZipOutputStream zout = new ZipOutputStream(checksum); // create object of FileInputStream for source file FileInputStream fin = new FileInputStream(filePath); zout.putNextEntry(new ZipEntry(filePath)); int length; while ((length = fin.read(buffer)) > 0) { zout.write(buffer, 0, length); } zout.closeEntry(); fin.close(); zout.close(); System.out.println("Zip file has been created!"); System.out.println("Adler32 Checksum is : " + checksum.getChecksum().getValue()); } catch (IOException ioe) { System.out.println("IOException : " + ioe); } } } |
Create Zip File With Adler32 Checksum, Java