Advertisement
Haulien

UnZip

May 8th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.zip.*;
  3.  
  4. public class UnZip {
  5.    final int BUFFER = 2048;
  6.    public static void main (String argv[]) {
  7.       try {
  8.          BufferedOutputStream dest = null;
  9.          FileInputStream fis = new
  10.        FileInputStream(argv[0]);
  11.          ZipInputStream zis = new
  12.        ZipInputStream(new BufferedInputStream(fis));
  13.          ZipEntry entry;
  14.          while((entry = zis.getNextEntry()) != null) {
  15.             System.out.println("Extracting: " +entry);
  16.             int count;
  17.             byte data[] = new byte[BUFFER];
  18.             // write the files to the disk
  19.             FileOutputStream fos = new
  20.           FileOutputStream(entry.getName());
  21.             dest = new
  22.               BufferedOutputStream(fos, BUFFER);
  23.             while ((count = zis.read(data, 0, BUFFER))
  24.               != -1) {
  25.                dest.write(data, 0, count);
  26.             }
  27.             dest.flush();
  28.             dest.close();
  29.          }
  30.          zis.close();
  31.       } catch(Exception e) {
  32.          e.printStackTrace();
  33.       }
  34.    }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement