In this example we are going to see How to Extract File With CRC32 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 52 | import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.zip.CRC32; import java.util.zip.CheckedInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class JavaExtractFileWithCRC32 { public static void main(String args[]) { String filePath = "C:/File/file.zip"; try { FileInputStream fileInputStream = new FileInputStream(filePath); CheckedInputStream checksum = new CheckedInputStream(fileInputStream, new CRC32()); ZipInputStream zin = new ZipInputStream(checksum); // get the first entry from the source zip file ZipEntry entry = zin.getNextEntry(); // crate OutputStream to extract the entry from zip file 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("CRC32 checksum is: " + checksum.getChecksum().getValue()); } catch (IOException e) { System.out.println("IOException :" + e); } } } |
Extract File With CRC32 Checksum, Java