Here you can find the source of unZipNoDirs(String file, String destinationDirectory)
Parameter | Description |
---|---|
argv | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void unZipNoDirs(String file, String destinationDirectory) throws IOException
//package com.java2s; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class Main { /**//from ww w. j a va 2 s . c o m * extracts a zip archive. Does not handle directories * kudos: http://java.sun.com/developer/technicalArticles/Programming/compression/ * @param argv * @throws IOException */ public static void unZipNoDirs(String file, String destinationDirectory) throws IOException { final int BUFFER = 2048; BufferedOutputStream dest = null; FileInputStream fis = new FileInputStream(file); ZipInputStream zis = new ZipInputStream( new BufferedInputStream(fis)); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { int count; byte data[] = new byte[BUFFER]; // write the files to the disk String destinationFilename = destinationDirectory + File.separator + entry.getName(); FileOutputStream fos = new FileOutputStream(destinationFilename); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); } zis.close(); } }