Home Tutorial Java Corejava Zip Show all the entries of zip file.

 
 

Share on Google+Share on Google+
Show all the entries of zip file.
Posted on: July 22, 2010 at 12:00 AM
Advertisement
In this tutorial you will see how to show all the entries of zip file.

Show all the entries of zip file.

In this tutorial, We will  discuss how to show all the entries of a zip file.  The ZipFile  
class is used to read entries of zip files. The entries() methods of ZipFile class 
returns enumeration of zip file entries. The getName() method of ZipFile class
class returns name of available entry. The hasMoreElements() of Enumeration 
class check the availability of more entries in zip file, and nextElement()  
method returns next element of entry . 

About ZipFile API:

The java.util.zip.ZipFile class extends java.io.FilterIntputStream class. It 
provides the following methods:

Return Type Method Description 
enumeration entries() The entries() method returns enumeration of entries of zip file. 
String getName() The getName() method returns  the name of zip file entries.

code

import java.io.*;
import java.util.zip.*;
import java.util.zip.ZipFile;
import java.util.zip.ZipEntry;
import java.util.Enumeration;
import java.io.IOException;

public class ShowEntries {
  public static void main(String args[]) {
    try {
      ZipFile zipName = new ZipFile("test.zip");
      Enumeration enumEntries = zipName.entries();
     System.out.println("List of contents  in zip file");
      while (enumEntries.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntryenumEntries.nextElement();
        String zipEntryName = zipEntry.getName();
        System.out.println(zipEntryName);
      }
      zipName.close();
    catch (IOException ioe) {
      System.out.println("IOException is :" + ioe);
    }
  }
}

Following is the output if you run the application

C:\>java ShowEntries
List contentsin zip file
testfile.txt
testfile1.txt

Download this code

Advertisement

Related Tags for Show all the entries of zip file.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 22, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com