Java如何读取zip文件的校验和值?
package org.nhooo.example.zip; import java.io.*; import java.util.zip.ZipInputStream; import java.util.zip.ZipEntry; import java.util.zip.CheckedInputStream; import java.util.zip.Adler32; public class UnzipWithChecksum { public static void main(String[] args) throws Exception { String zipName = "data-1.zip"; try (FileInputStream fis = new FileInputStream(zipName); //创建输入流,该输入流还保持以下项的校验和 //以后可以用来验证数据的数据 //诚信 CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32()); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum))) { ZipEntry entry; //从ZipInputStream读取每个条目,直到没有更多条目为止 //找到,由getNextEntry()的空返回值指示 //方法。 while ((entry = zis.getNextEntry()) != null) { System.out.println("Unzipping: " + entry.getName()); int size; byte[] buffer = new byte[1048]; try (FileOutputStream fos = new FileOutputStream(entry.getName()); BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length)) { while ((size = zis.read(buffer, 0, buffer.length)) != -1) { bos.write(buffer, 0, size); } bos.flush(); } } //打印校验和值 long value = checksum.getChecksum().getValue(); System.out.println("Checksum = " + value); } } }