Reputation: 1953
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
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
Reputation: 7871
You can use the checksumCRC32
method from the FileUtils
class in org.apache.commons.io
package.
Upvotes: 4