How to Get CRC32 Checksum of Zip Entry in Java


In this example we will show how to get CRC-32 checksum of zip entry with getCrc method of java ZipEntry class.

Source Code

package com.beginner.examples;

import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
 
 
public class ZipCRC32Example {
	
	public static void main(String args[])
	{		 
		try
		{
		    //open a zip file
			ZipFile zipFile = new ZipFile("D:/Workspaces/test.zip");
		   
		    Enumeration en = zipFile.entries();
			
			while(en.hasMoreElements())
			{
				ZipEntry zip = (ZipEntry)en.nextElement();
				//get name of an entry
				String name = zip.getName();
				
				System.out.println(name);
				
				//get CRC-32 checksum of an entry
				long crc = zip.getCrc();

				System.out.println(crc);
							
			}
	 	 
			zipFile.close();
		 	
		 }
		 catch(IOException e)
		 {
			 e.printStackTrace();
		 }
	}
 
}

Output:

test.txt
3093599594

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments