Get CRC-32 Checksum of Zip Entry - Java File Path IO

Java examples for File Path IO:Zip File

Description

Get CRC-32 Checksum of Zip Entry

Demo Code


import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {

  public static void main(String args[]) {
    try {/*from   ww  w. j  av  a 2  s . c om*/
      ZipFile zipFile = new ZipFile("c:/Folder/WebFiles.zip");
      Enumeration e = zipFile.entries();

      System.out.print("File Name");
      System.out.print("\t\t\t\tCRC-32 Checksum");

      while (e.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) e.nextElement();

        String entryName = entry.getName();
        long crc = entry.getCrc();

        System.out.print(entryName);
        System.out.print("\t\t\t\t" + crc);
        System.out.print("\n");

      }

      zipFile.close();

    } catch (IOException ioe) {
      System.out.println("Error opening zip file" + ioe);
    }
  }

}

Result


Related Tutorials