Get Zip Entry Example

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

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!