/*
Get Modification Time of Zip Entry Example
This Java example shows how to get modification time of particular entry
(i.e. file or directory) using getTime method of
Java ZipEntry class.
*/
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class GetModificationTime {
public static void main(String args[])
{
try
{
/*
* To Open a zip file, use
*
* ZipFile(String fileName)
* constructor of the ZipFile class.
*
* This constructor throws IOException for any I/O error.
*/
ZipFile zipFile = new ZipFile("c:/FileIO/WebFiles.zip");
/*
* Get list of zip entries using entries method of
* ZipFile class.
*/
Enumeration e = zipFile.entries();
System.out.print("File Name");
System.out.print("\t\t\t\tModification Time");
System.out.print("\n---------------------------------\n");
while(e.hasMoreElements())
{
ZipEntry entry = (ZipEntry)e.nextElement();
/*
* To get Modification time of an entry, use
*
* long getTime()
* method of ZipEntry class.
*
* This method returns the modification time in long.
* We need to convert it to date.
*/
String entryName = entry.getName();
Date modificationTime = new Date(entry.getTime());
System.out.print(entryName);
System.out.print("\t\t\t\t" + modificationTime);
System.out.print("\n");
}
/*
* close the opened zip file using,
* void close()
* method.
*/
zipFile.close();
}
catch(IOException ioe)
{
System.out.println("Error opening zip file" + ioe);
}
}
}
/*
Output of this program would be
File Name Modification Time
---------------------------------
css/datagrid.css Sun Apr 19 17:03:00 IST 2009
css/graph.css Sun Apr 19 17:03:00 IST 2009
jsps/Masthead.jspf Thu Apr 23 17:24:44 IST 2009
jsps/Welcome.jsp Tue Apr 28 14:48:28 IST 2009
*/