Over 500 Magazines for FREE!

Yes! You can subscribe to ALL of them. They will be shipped to your home FREE of cost!
Kindly click here to apply!

Get CRC-32 Checksum of Zip Entry Example

  1. /*
  2. Get CRC-32 Checksum of Zip Entry Example
  3. This Java example shows how to get CRC-32 checksum of zip entry
  4. using getCrc method of Java ZipEntry class.
  5. */
  6.  
  7. import java.io.IOException;
  8. import java.util.Enumeration;
  9. import java.util.zip.ZipEntry;
  10. import java.util.zip.ZipFile;
  11.  
  12.  
  13. public class GetCRC32Checksum {
  14.  
  15. public static void main(String args[])
  16. {
  17. try
  18. {
  19. /*
  20. * To Open a zip file, use
  21. *
  22. * ZipFile(String fileName)
  23. * constructor of the ZipFile class.
  24. *
  25. * This constructor throws IOException for any I/O error.
  26. */
  27. ZipFile zipFile = new ZipFile("c:/FileIO/WebFiles.zip");
  28.  
  29. /*
  30. * Get list of zip entries using entries method of
  31. * ZipFile class.
  32. */
  33.  
  34. Enumeration e = zipFile.entries();
  35.  
  36. System.out.print("File Name");
  37. System.out.print("\t\t\t\tCRC-32 Checksum");
  38. System.out.print("\n---------------------------------\n");
  39.  
  40. while(e.hasMoreElements())
  41. {
  42. ZipEntry entry = (ZipEntry)e.nextElement();
  43.  
  44. /*
  45. * To get CRC-32 checksum of an entry, use
  46. *
  47. * long getCrc()
  48. * method of Java ZipEntry class.
  49. *
  50. * This method returns the CRC checksum for a particular
  51. * zip entry, or -1 if not known.
  52. */
  53.  
  54. String entryName = entry.getName();
  55. long crc = entry.getCrc();
  56.  
  57. System.out.print(entryName);
  58. System.out.print("\t\t\t\t" + crc);
  59. System.out.print("\n");
  60.  
  61. }
  62.  
  63. /*
  64. * close the opened zip file using,
  65. * void close()
  66. * method.
  67. */
  68.  
  69. zipFile.close();
  70.  
  71. }
  72. catch(IOException ioe)
  73. {
  74. System.out.println("Error opening zip file" + ioe);
  75. }
  76. }
  77.  
  78. }
  79.  
  80. /*
  81. Output of this program would be
  82. File Name CRC-32 Checksum
  83. ---------------------------------
  84. css/datagrid.css 995618961
  85. css/graph.css 2675857370
  86. jsps/Masthead.jspf 1211369105
  87. jsps/Welcome.jsp 665174626
  88. */

Post new comment

To combat spam, please enter the code in the image.




Do you have a better example?
We're sure you have hundreds of Java program examples.

Spare some time and submit your java example here even if you think it's too small to contribute.

Could not find what you are looking for? Search Java Examples




Feel Tired? Read Jokes & Inspirational Stories, Play Games!