Java ZipOutputStream Write zipFile(ZipOutputStream zipOut, String path, File file)

Here you can find the source of zipFile(ZipOutputStream zipOut, String path, File file)

Description

zip File

License

Open Source License

Declaration

public static void zipFile(ZipOutputStream zipOut, String path, File file) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

import java.util.zip.*;

public class Main {
    public static void zipFile(ZipOutputStream zipOut, String path, File file) throws IOException {

        if (!file.canRead()) {
            System.out.println("Cannot read " + file.getCanonicalPath() + " (maybe because of permissions)");
            return;
        }//from ww w . j av  a  2  s  .c  om

        System.out.println("Compressing " + file.getName());
        zipOut.putNextEntry(new ZipEntry(file.getName()));

        FileInputStream fis = new FileInputStream(file);

        byte[] buffer = new byte[4092];
        int byteCount = 0;
        while ((byteCount = fis.read(buffer)) != -1) {
            zipOut.write(buffer, 0, byteCount);
            System.out.print('.');
            System.out.flush();
        }
        System.out.println();

        fis.close();
        zipOut.closeEntry();
    }
}

Related

  1. zip(final File directory, final File base, final ZipOutputStream zipOutputStream)
  2. zipAutoBase(File f, File base, ZipOutputStream out)
  3. zipFile(ZipOutputStream out, File file, String dir)
  4. zipFile(ZipOutputStream out, File sourceFile)
  5. zipFile(ZipOutputStream out, String stripPath, File file, char pathSeparator)
  6. zipFile(ZipOutputStream zos, BufferedOutputStream out, File destPath, String originalPath)
  7. zipFile(ZipOutputStream zos, File file, String requestName, byte[] buf)
  8. zipFile(ZipOutputStream zout, File file, int rootLength)
  9. zipInternal(String path, File file, ZipOutputStream os)