/*
Get Zip Entry Example
This Java example shows how to get comment for specified
zip entry or all zip entries using getComment method of Java
ZipEntry class.
*/
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class GetComment {
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();
while(e.hasMoreElements())
{
ZipEntry entry = (ZipEntry)e.nextElement();
/*
* To get comment associated with zip entry or
* archived file, use
*
* String getComment() method of ZipEntry Class.
*
* This method returns null if no comment is specified
* for particular entry.
*/
String comment = entry.getComment();
if("".equals(comment))
System.out.println(comment + " found for entry " + entry.getName());
else
System.out.println("No comments found for entry " + entry.getName());
}
/*
* 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,
No comments found for entry css/datagrid.css
No comments found for entry css/graph.css
No comments found for entry css/icons.css
No comments found for entry jsps/Masthead.jspf
No comments found for entry jsps/Welcome.jsp
*/