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 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. */

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!