我不确定我的概念是否正确,但我知道我们可以通过获取每个条目的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());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2300 次 |
| 最近记录: |