Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

Listing Contents of a ZIP File

This section, provides the way for listing all the elements of a zip file through the java code.

Ads

Tutorials   
How to read properties file in Java? Generate random numbers in Java Cloneable Interface in Java What is the flaw with the Stack class? List In Java Java Stack Example HashSet In Java Enumeration in java How to generate random number in java Iterator in java Queue in java Transient Java Keyword clone method in Java Java Queue example Logger in Java Java current date - How to get current date in Java Collection : LinkedList Example Collection : ArrayList Example Random alpha numeric string of fixed size Java List Iterator Example The Hashtable Class The BitSet class Java Vector Java Enumeration Data Structures in Java Java Transient Variable Java Date Format Example Java Properties File Example Map.Entry Java Interface Java Property File java preferences,Change the value of Preferences by user Retrieving a Preference Node Java hasNext Write Keys and Values to the Properties file in Java Get All Keys and Values of the Properties files in Java Properties file in Java Properties file in Java Determining If a Preference Node Contains a Specific Value Change the value of Preferences by user Clone method example in Java Implementing a Simple Event Notifier Determining When a Preference Node Is Added or Removed Listening for Changes to Preference Values in a Preference Node Importing Preferences Finding a Preference in a Preference Tree Retrieving the Parent and Child Nodes of a Preference Node Determining If a Preference Node Exists Removing a Preference Node Creating a Preference Node Getting the Maximum Size of a Preference Key and Value
Ads

Listing Contents of a ZIP File

     

Section, provides the way for listing all the elements of a zip file through the java code. Following program helps you for the appropriate. You can directly copy and paste the code in your java application for showing list of elements present in the zip file format.

Program Result:

This program takes a zip file name and checks it for the zip format ('.zip' extension) and also checks whether the given file exists or not in your specified or default directory. Then it shows the list of the elements of the zip file.

Code Description:

ZipFile:
This is the class of java.util.zip.*; package. This class is used to read the zip file entries.

Here is the code of the program:

import java.util.*;
import java.util.zip.*;
import java.io.*;

public class ListZipFiles{
  public static void main(String[] argsthrows IOException{
  ListZipFiles zf = new ListZipFiles();
  }

  public ListZipFiles() throws IOException{
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  System.out.print("Enter Zip file name: ");
  String filename = in.readLine();
//  File file = new File(filename);
  if(!filename.endsWith(".zip")){
  System.out.println("Invalid file name!");
  System.exit(0);
  }
  else if(!new File(filename).exists()){
  System.out.println("File not exist!");
  System.exit(0);
  }

  try{
  ZipFile zipFile = new ZipFile(filename);
  Enumeration em = zipFile.entries();
  for (Enumeration em1 = zipFile.entries(); em1.hasMoreElements();) {
  System.out.println(em1.nextElement());
  }
  }
  catch(ZipException ze){
  System.out.println(ze.getMessage());
  System.out.println("Zip file may be corrupted.");
  System.exit(0);
  }
  }

Download this example.

Advertisements

Ads
Share on Google+Share on Google+

Listing Contents of a ZIP File

Posted on: April 16, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Listing Contents of a ZIP File  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads