Example usage for java.util.zip ZipInputStream ZipInputStream

List of usage examples for java.util.zip ZipInputStream ZipInputStream

Introduction

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

Prototype

public ZipInputStream(InputStream in) 

Source Link

Document

Creates a new ZIP input stream.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ZipInputStream in = new ZipInputStream(new FileInputStream("source.zip"));
    OutputStream out = new FileOutputStream("target");
    byte[] buf = new byte[1024];
    int len;/*from w  ww .j a v  a  2  s.  co m*/
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    out.close();
    in.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fis = new FileInputStream("C:/MyZip.zip");
    ZipInputStream zis = new ZipInputStream(fis);
    ZipEntry ze;//  ww w .  j  a  v  a  2  s.  co m
    while ((ze = zis.getNextEntry()) != null) {
        System.out.println(ze.getName());
        zis.closeEntry();
    }

    zis.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipInputStream inStream = new ZipInputStream(new FileInputStream("compressed.zip"));
    OutputStream outStream = new FileOutputStream("extracted.txt");

    byte[] buffer = new byte[1024];
    int read;/*www . j a v  a 2s .  c  o m*/
    ZipEntry entry;
    if ((entry = inStream.getNextEntry()) != null) {
        while ((read = inStream.read(buffer)) > 0) {
            outStream.write(buffer, 0, read);
        }
    }
    outStream.close();
    inStream.close();
}

From source file:ZipReader.java

public static void main(String[] args) throws Exception {
    ZipInputStream zis = null;/* w  w  w  .  j av  a 2 s  .  c o  m*/

    FileInputStream fis = new FileInputStream(args[0]);
    zis = new ZipInputStream(fis);

    ZipEntry ze;

    while ((ze = zis.getNextEntry()) != null)
        System.out.println(ze.getName());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);
    ZipInputStream zis = new ZipInputStream(fis);

    ZipEntry ze;//  w  ww .  jav  a 2 s  . co m
    while ((ze = zis.getNextEntry()) != null)
        System.out.println(
                ze.getName() + "  [" + ze.getSize() + "]  [" + new Date(ze.getTime()).toString() + "]");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipInputStream zipinputstream = new ZipInputStream(new FileInputStream("filename"));
    ZipEntry zipentry = zipinputstream.getNextEntry();
    while (zipentry != null) {
        String entryName = zipentry.getName();
        File newFile = new File(entryName);
        String directory = newFile.getParent();
        if (directory == null) {
            if (newFile.isDirectory())
                break;
        }//from  w ww.j a v  a2  s .c o m
        RandomAccessFile rf = new RandomAccessFile(entryName, "r");
        String line;
        if ((line = rf.readLine()) != null) {
            System.out.println(line);
        }
        rf.close();
        zipinputstream.closeEntry();
        zipentry = zipinputstream.getNextEntry();
    }
    zipinputstream.close();
}

From source file:ZipReader.java

public static void main(String[] args) throws Exception {
    ZipInputStream zis = null;/*from   ww  w. ja  v a2 s.  c  o m*/

    FileInputStream fis = new FileInputStream(args[0]);
    zis = new ZipInputStream(fis);

    ZipEntry ze;

    while ((ze = zis.getNextEntry()) != null)
        System.out.println(
                ze.getName() + "  [" + ze.getSize() + "]  [" + new Date(ze.getTime()).toString() + "]");
}

From source file:Main.java

  public static void main(String[] argv) throws Exception {
  String inFilename = "infile.zip";
  ZipInputStream in = new ZipInputStream(new FileInputStream(inFilename));

  ZipEntry entry = in.getNextEntry();

  String outFilename = "o";
  OutputStream out = new FileOutputStream(outFilename);

  byte[] buf = new byte[1024];
  int len;/*w  w w.  j  av a2s. c om*/
  while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
  }

  out.close();
  in.close();
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {

    for (int i = 0; i < args.length; i++) {
        FileInputStream fin = new FileInputStream(args[i]);
        ZipInputStream zin = new ZipInputStream(fin);
        ZipEntry ze = null;/* w  w w . ja  v a  2 s.c o m*/
        while ((ze = zin.getNextEntry()) != null) {
            System.out.println("Unzipping " + ze.getName());
            FileOutputStream fout = new FileOutputStream(ze.getName());
            for (int c = zin.read(); c != -1; c = zin.read()) {
                fout.write(c);
            }
            zin.closeEntry();
            fout.close();
        }
        zin.close();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String zipname = "data.zip";
    FileInputStream fis = new FileInputStream(zipname);
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
    ZipEntry entry;//  w  w w.  j  ava 2s.co  m

    while ((entry = zis.getNextEntry()) != null) {
        System.out.println("Unzipping: " + entry.getName());

        int size;
        byte[] buffer = new byte[2048];

        FileOutputStream fos = new FileOutputStream(entry.getName());
        BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);

        while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
    }
    zis.close();
    fis.close();
}