List Contents Of Zip File Example

  1. /*
  2. List Contents Of Zip File Example
  3. This Java example shows how to list contents of zip file
  4. using entries method of Java ZipFile class.
  5. */
  6.  
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.util.Enumeration;
  10. import java.util.zip.ZipEntry;
  11. import java.util.zip.ZipFile;
  12.  
  13. public class ListContentsZipFile {
  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. * To get list of entries in the zip file, use
  31. *
  32. * Enumeration entries()
  33. * method of ZipFile class.
  34. */
  35.  
  36. Enumeration e = zipFile.entries();
  37.  
  38. System.out.println("Listing zip file contents");
  39. while(e.hasMoreElements())
  40. {
  41. ZipEntry entry = (ZipEntry)e.nextElement();
  42. System.out.println(entry.getName());
  43. }
  44.  
  45. }
  46. catch(IOException ioe)
  47. {
  48. System.out.println("Error opening zip file" + ioe);
  49. }
  50.  
  51. }
  52. }
  53.  
  54. /*
  55. Output would be
  56. Listing zip file contents
  57. css/datagrid.css
  58. css/graph.css
  59. jsps/Masthead.jspf
  60. jsps/Welcome.jsp
  61. */

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!