Get Modification Time of Zip Entry Example

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

Visit Java Example Forums to request Java examples or ask Java questions!
OR
Try out our new Java Search Engine




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!