/*
Get CRC-32 Checksum of Zip Entry Example
This Java example shows how to get CRC-32 checksum of zip entry
using getCrc method of Java ZipEntry class.
*/
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class GetCRC32Checksum {
public static void main(String args[])
{
try
{
/*
* To Open a zip file, use
*
* ZipFile(String fileName)
* constructor of the ZipFile class.
*
* This constructor throws IOException for any I/O error.
*/
ZipFile zipFile = new ZipFile("c:/FileIO/WebFiles.zip");
/*
* Get list of zip entries using entries method of
* ZipFile class.
*/
Enumeration e = zipFile.entries();
System.out.print("File Name");
System.out.print("\t\t\t\tCRC-32 Checksum");
System.out.print("\n---------------------------------\n");
while(e.hasMoreElements())
{
ZipEntry entry = (ZipEntry)e.nextElement();
/*
* To get CRC-32 checksum of an entry, use
*
* long getCrc()
* method of Java ZipEntry class.
*
* This method returns the CRC checksum for a particular
* zip entry, or -1 if not known.
*/
String entryName = entry.getName();
long crc = entry.getCrc();
System.out.print(entryName);
System.out.print("\t\t\t\t" + crc);
System.out.print("\n");
}
/*
* close the opened zip file using,
* void close()
* method.
*/
zipFile.close();
}
catch(IOException ioe)
{
System.out.println("Error opening zip file" + ioe);
}
}
}
/*
Output of this program would be
File Name CRC-32 Checksum
---------------------------------
css/datagrid.css 995618961
css/graph.css 2675857370
jsps/Masthead.jspf 1211369105
jsps/Welcome.jsp 665174626
*/
Post new comment