Java Unzip ZipEntry unzipSingleEntry(ZipInputStream zin, File toFile)

Here you can find the source of unzipSingleEntry(ZipInputStream zin, File toFile)

Description

Will unzip next entry from given ZipInputStream

License

Open Source License

Declaration

private static void unzipSingleEntry(ZipInputStream zin, File toFile) throws IOException 

Method Source Code

//package com.java2s;
/*//w  ww . j av a2s .  com
   Copyright (c) 2011 Robin Vobruba <hoijui.quaero@gmail.com>
    
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
    
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
    
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.util.zip.ZipInputStream;

public class Main {
    /**
     * Will unzip next entry from given ZipInputStream
     */
    private static void unzipSingleEntry(ZipInputStream zin, File toFile) throws IOException {
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(toFile);
            byte[] b = new byte[512];
            int len = 0;
            while ((len = zin.read(b)) != -1) {
                out.write(b, 0, len);
            }
        } finally {
            out.close();
        }
    }
}

Related

  1. unzipEntry(ZipInputStream zis, File out)
  2. unzipEntry(ZipInputStream zis, File targetFile)
  3. unzipEntryToFolder(ZipEntry entry, InputStream zis, File destFolder)
  4. unZipFile(File destFile, ZipFile zipFile, ZipEntry entry)
  5. unzipFile(ZipFile archive, File targetFile, ZipEntry entry)