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.


Suggested Reading

Oracle Magazine
Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.
Cost: FREE

View/Subscribe
NASA Tech Briefs
Features exclusive reports of innovations developed by NASA and its industry partners/contractors that can be applied to develop new/improved products and solve engineering or manufacturing problems.
Cost: FREE

View/Subscribe
FierceBiotech IT
Is a free, easy to read weekly email service that brings must read biotech IT news to senior biotech, pharma, and IT executives.
Cost: FREE

View/Subscribe
Simply SQL
Simply SQL is a practical step-by-step guide to writing SQL.
Cost: FREE

View/Subscribe
Simply JavaScript
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Cost: FREE

View/Subscribe
PCMag.com's What's New Now
Lance Ulanoff, Editor in Chief of the PC Magazine Network, brings you this twice-weekly roundup of the latest top tech stories, the best new product reviews, plus special offers from Ziff Davis and its partners.
Cost: FREE

View/Subscribe

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




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