[英]Is it possible to determine the CRC of a zip file ?
我不确定我的概念是否正确,但我知道我们可以通过获取每个条目的CRC值来验证zip文件的完整性。 但是,我的问题是,如果我得到一个zip文件,它会有CRC吗?如果有,我该如何确定?
您可以使用java.util.zip.CRC32
为任何数据流计算CRC-32校验和。
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());
您可以使用org.apache.commons.io
包中的FileUtils
类的checksumCRC32
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.