List Contents Of Zip File Example
- /*
- List Contents Of Zip File Example
- This Java example shows how to list contents of zip file
- using entries method of Java ZipFile 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 ListContentsZipFile {
- 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");
- /*
- * To get list of entries in the zip file, use
- *
- * Enumeration entries()
- * method of ZipFile class.
- */
- Enumeration e = zipFile.entries();
- System.out.println("Listing zip file contents");
- while(e.hasMoreElements())
- {
- ZipEntry entry = (ZipEntry)e.nextElement();
- System.out.println(entry.getName());
- }
- }
- catch(IOException ioe)
- {
- System.out.println("Error opening zip file" + ioe);
- }
- }
- }
- /*
- Output would be
- Listing zip file contents
- css/datagrid.css
- css/graph.css
- jsps/Masthead.jspf
- jsps/Welcome.jsp
- */



