Java Path Extract nio extractFile(ZipInputStream zipIn, Path filePath)

Here you can find the source of extractFile(ZipInputStream zipIn, Path filePath)

Description

Extracts a zip entry (file entry)

License

Creative Commons License

Parameter

Parameter Description
zipIn a parameter
filePath a parameter

Exception

Parameter Description
IOException an exception

Declaration

private static void extractFile(ZipInputStream zipIn, Path filePath) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.io.BufferedOutputStream;

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

import java.nio.file.Path;

import java.util.zip.ZipInputStream;

public class Main {
    /**/*from w ww  . j  a v  a  2s  .c o  m*/
     * Size of the buffer to read/write data
     */
    private static final int BUFFER_SIZE = 4096;

    /**
     * Extracts a zip entry (file entry)
     * 
     * @param zipIn
     * @param filePath
     * @throws IOException
     */
    private static void extractFile(ZipInputStream zipIn, Path filePath) throws IOException {
        BufferedOutputStream bos = new BufferedOutputStream(
                new FileOutputStream(filePath.toFile().getAbsolutePath()));
        byte[] bytesIn = new byte[BUFFER_SIZE];
        int read = 0;
        while ((read = zipIn.read(bytesIn)) != -1) {
            bos.write(bytesIn, 0, read);
        }
        bos.close();
    }
}

Related

  1. extract(Path archive, Path targetDirectory)
  2. extractClassName(Path path)
  3. extractCurrentPath()
  4. extractLanguageRelativePath(final Path absolutePath)
  5. extractLuaStacktrace(Path path, StackTraceElement[] stackTrace)
  6. extractVersion(Path pathToBinaries)
  7. extractZipArchive(final File zipFile, Path destDir)