Here you can find the source of unzip(InputStream inputStream, String outputFolder)
Parameter | Description |
---|---|
inputStream | a parameter |
outputFolder | a parameter |
public static void unzip(InputStream inputStream, String outputFolder)
//package com.java2s; //License from project: Apache License import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class Main { public static final String SEPARATOR = "/"; /**// w ww . jav a 2 s .c o m * Unzips a file all into one directory * * @param inputStream * @param outputFolder */ public static void unzip(InputStream inputStream, String outputFolder) { byte[] buffer = new byte[1024]; try { File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } ZipInputStream zis = new ZipInputStream(inputStream); ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); if (ze.isDirectory()) { ze = zis.getNextEntry(); continue; } fileName = new File(fileName).getName(); File newFile = new File(outputFolder + SEPARATOR + fileName); new File(newFile.getParent()).mkdirs(); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (IOException ex) { } } }