Share on Google+Share on Google+

How to search entry in ZipFile.

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 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.



class SearchEntry {
  public static void main(String[] args) {
    try {
      String zipFile = "";
      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


Posted on: July 22, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.


Advertisement null