Home Tutorial Java Corejava Zip How to search entry in ZipFile.

 
 

Share on Google+Share on Google+
How to search entry in ZipFile.
Posted on: July 22, 2010 at 12:00 AM
Advertisement
In this tutorial you will see how to search entry in ZipFile.

How to search entry in ZipFile.

In this tutorial, We will discuss the use of getEntry() method. The getEntry() methods are 
available in ZipFile class, and it is used to read entries of zip files. 

In this Example, we will search given entry in a zip file. The getEntry method search specific 
entry in a zip file, and returns specified entry or null if it not available in it. 

About ZipFile API:

The java.util.zip.ZipFile class extends javalang.Object class. It provides the following methods:

Return Type Method Description 
ZipEntry getEntry() The getEntry() method  returns given name entry if entry found otherwise null if entry not found.

code

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

class SearchEntry {
  public static void main(String[] args) {
    try {
      String zipFile = "test.zip";
      String searchEntry = "bharat.txt";
      ZipFile name = new ZipFile(zipFile);
      if (name.getEntry(searchEntry!= null) {
System.out.println("Entry  name " +

                   searchEntry + " is found.");
      else {
   System.out.println("Entry  name " + searchEntry
            " is not found.");
      }

    catch (IOException e) {
      System.out.println("There is a error");
    }
  }

}

Following is the output if you run the application

C:\>java SearchEntry
Entry name bharat.txt is found.

Download this code

Advertisement

Related Tags for How to search entry in ZipFile.:


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