Get Compression Method of Zip Entry - Java File Path IO

Java examples for File Path IO:Zip File

Description

Get Compression Method of Zip Entry

Demo Code


import java.io.File;
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[])
        {                /*  w w  w. j a  v  a2 s .  c  om*/
                try
                {
                   ZipFile zipFile = new ZipFile("c:/Folder/WebFiles.zip");
                   
                        Enumeration e = zipFile.entries();
                        while(e.hasMoreElements())
                        {
                                ZipEntry entry = (ZipEntry)e.nextElement();
                                 int method = entry.getMethod();
                                 
                                 if(method == ZipEntry.DEFLATED)
                                        System.out.println(entry.getName() + "\t\t\t\tDeflated");
                                 else if(method == ZipEntry.STORED)
                                        System.out.println(entry.getName() + "\t\t\t\tStored");
                                 else if(method == -1)
                                        System.out.println(entry.getName() + "\t\t\t\tNot Specified");
                                                               
                        }
                          zipFile.close();
                       
                 }
                 catch(IOException ioe)
                 {
                        System.out.println("Error opening zip file" + ioe);
                 }
        }
 
}

Result


Related Tutorials