Example usage for java.util.zip ZipFile entries

List of usage examples for java.util.zip ZipFile entries

Introduction

In this page you can find the example usage for java.util.zip ZipFile entries.

Prototype

public Enumeration<? extends ZipEntry> entries() 

Source Link

Document

Returns an enumeration of the ZIP file entries.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zipFile = new ZipFile(new File("testfile.zip"));

    Enumeration zipEntries = zipFile.entries();

    while (zipEntries.hasMoreElements()) {
        System.out.println(((ZipEntry) zipEntries.nextElement()).getName());
    }/*from w w  w.j a  v  a 2 s  .c  o  m*/
}

From source file:MainClass.java

public static void main(String[] args) {

    try {/* ww  w.  ja v  a  2  s.c  o m*/
        ZipFile zf = new ZipFile("your.zip");
        Enumeration e = zf.entries();
        while (e.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) e.nextElement();
            String name = ze.getName();
            Date lastModified = new Date(ze.getTime());
            long uncompressedSize = ze.getSize();
            long compressedSize = ze.getCompressedSize();

            System.out.println(name);
            System.out.println(lastModified);
            System.out.println(uncompressedSize);
            System.out.println(compressedSize);

        }
    } catch (IOException ex) {
        System.err.println(ex);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String zipname = "data.zip";
    ZipFile zipFile = new ZipFile(zipname);
    Enumeration enumeration = zipFile.entries();
    while (enumeration.hasMoreElements()) {
        ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
        System.out.println("Unzipping: " + zipEntry.getName());
        BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
        int size;
        byte[] buffer = new byte[2048];
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(zipEntry.getName()),
                buffer.length);//from   w w w.ja v a 2 s.c o m
        while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
        bis.close();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zf = new ZipFile("your.zip");
    Enumeration e = zf.entries();
    while (e.hasMoreElements()) {
        ZipEntry ze = (ZipEntry) e.nextElement();
        String name = ze.getName();

        Date lastModified = new Date(ze.getTime());
        long uncompressedSize = ze.getSize();
        long compressedSize = ze.getCompressedSize();

        int method = ze.getMethod();

        if (method == ZipEntry.STORED) {
            System.out.println(name + " was stored at " + lastModified);
            System.out.println("with a size of  " + uncompressedSize + " bytes");
        } else if (method == ZipEntry.DEFLATED) {
            System.out.println(name + " was deflated at " + lastModified);
            System.out.println("from  " + uncompressedSize + " bytes to " + compressedSize
                    + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%");
        } else {//w  w  w .ja  v  a  2  s.  co  m
            System.out.println(name + " was compressed at " + lastModified);
            System.out.println("from  " + uncompressedSize + " bytes to " + compressedSize
                    + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%");
        }
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    try {/*from   w ww .  j a v  a 2  s . c  o  m*/
        ZipFile zf = new ZipFile("your.zip");
        Enumeration e = zf.entries();
        while (e.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) e.nextElement();
            String name = ze.getName();

            long crc = ze.getCrc();
            System.out.println("Its CRC is " + crc);

            String comment = ze.getComment();
            if (comment != null && !comment.equals("")) {
                System.out.println(comment);
            }
            if (ze.isDirectory()) {
                System.out.println(name + " is a directory");
            }
        }
    } catch (IOException ex) {
        System.err.println(ex);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zip = new ZipFile(new File("sample.zip"));

    for (Enumeration e = zip.entries(); e.hasMoreElements();) {
        ZipEntry entry = (ZipEntry) e.nextElement();
        System.out.println("File name: " + entry.getName() + "; size: " + entry.getSize()
                + "; compressed size: " + entry.getCompressedSize());
        InputStream is = zip.getInputStream(entry);
        InputStreamReader isr = new InputStreamReader(is);

        char[] buffer = new char[1024];
        while (isr.read(buffer, 0, buffer.length) != -1) {
            String s = new String(buffer);
            System.out.println(s.trim());
        }/* ww w.ja  va2s  . c  om*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zf = new ZipFile("a.zip");
    Enumeration e = zf.entries();
    while (e.hasMoreElements()) {
        ZipEntry ze = (ZipEntry) e.nextElement();
        String name = ze.getName();

        long uncompressedSize = ze.getSize();
        long compressedSize = ze.getCompressedSize();
        long crc = ze.getCrc();
        int method = ze.getMethod();
        String comment = ze.getComment();

        System.out.println(name + " was stored at " + new Date(ze.getTime()));
        if (method == ZipEntry.STORED) {
            System.out.println("with a size of  " + uncompressedSize + " bytes");
        } else if (method == ZipEntry.DEFLATED) {
            System.out.println("from " + uncompressedSize + " bytes to " + compressedSize);
        } else {/*w  w  w .  j av  a 2 s.c o m*/
            System.out.println("from " + uncompressedSize + " bytes to " + compressedSize);
        }
        System.out.println("Its CRC is " + crc);
        if (comment != null && !comment.equals("")) {
            System.out.println(comment);
        }
        if (ze.isDirectory()) {
            System.out.println(name + " is a directory");
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zipFile = new ZipFile("testfile.zip", Charset.defaultCharset());

    Enumeration zipEntries = zipFile.entries();

    while (zipEntries.hasMoreElements()) {
        System.out.println(((ZipEntry) zipEntries.nextElement()).getName());
    }//w w  w . j a  v  a  2  s  .co  m
    zipFile.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zipFile = new ZipFile(new File("testfile.zip"), ZipFile.OPEN_READ);

    Enumeration zipEntries = zipFile.entries();

    while (zipEntries.hasMoreElements()) {
        System.out.println(((ZipEntry) zipEntries.nextElement()).getName());
    }// w  w w . j  a va 2s  . c o m
}

From source file:ReadZip.java

public static void main(String args[]) {
    try {/*  w ww  .  j av  a  2s  .  c om*/
        ZipFile zf = new ZipFile("ReadZip.zip");
        Enumeration entries = zf.entries();

        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        while (entries.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) entries.nextElement();
            System.out.println("Read " + ze.getName() + "?");
            String inputLine = input.readLine();
            if (inputLine.equalsIgnoreCase("yes")) {
                long size = ze.getSize();
                if (size > 0) {
                    System.out.println("Length is " + size);
                    BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
                    String line;
                    while ((line = br.readLine()) != null) {
                        System.out.println(line);
                    }
                    br.close();
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}