Determine if the Zip Entry Is Directory - Java File Path IO

Java examples for File Path IO:Zip File

Description

Determine if the Zip Entry Is Directory

Demo Code

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

public class Main {

  public static void main(String args[]) {
    try {// w w w .  ja  v  a 2s.c  o m
      ZipFile zipFile = new ZipFile("c:/Folder/Files.zip");
      Enumeration e = zipFile.entries();

      System.out.print("File Name");
      System.out.print("\t\t\t\tIs Directory");

      while (e.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) e.nextElement();

        String entryName = entry.getName();
        boolean isDir = entry.isDirectory();

        System.out.print(entryName);
        System.out.print("\t\t\t\t" + isDir);
        System.out.print("\n");

      }
      zipFile.close();

    } catch (IOException ioe) {
      System.out.println("Error opening zip file" + ioe);
    }
  }

}
 

Result


Related Tutorials