Nikhil Das Nomula
Nikhil Das Nomula

Reputation: 1953

Is it possible to determine the CRC of a zip file ?

I am not sure if I got the concept right, but I know that we can verify that the integrity of the files in a zip by getting the CRC values for each entry. However, my question is if I get a zip file, will there be a CRC for it and if so how can I determine that ?

Upvotes: 6

Views: 4354

Answers (2)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51721

You can use java.util.zip.CRC32 to compute CRC-32 checksum for any data stream.

BufferedInputStream bis = new BufferedInputStream(
                          new FileInputStream(new File("/path/to/file.zip"))); 
int read = 0;
CRC32 checksum = new CRC32();
byte[] buffer = new byte[1024];
while ((read = bis.read(buffer)) != -1) {
    checksum.update(buffer, 0, read);
}
bis.close();
System.out.println ("CRC32 of your zip is: " + checksum.getValue());

Upvotes: 6

JHS
JHS

Reputation: 7871

You can use the checksumCRC32 method from the FileUtils class in org.apache.commons.io package.

Upvotes: 4

Related Questions