Java ZipOutputStream Write zipAutoBase(File f, File base, ZipOutputStream out)

Here you can find the source of zipAutoBase(File f, File base, ZipOutputStream out)

Description

zip Auto Base

License

Open Source License

Declaration

private static void zipAutoBase(File f, File base, ZipOutputStream out)
            throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class Main {
    private static void zipAutoBase(File f, File base, ZipOutputStream out)
            throws FileNotFoundException, IOException {
        if (f.isDirectory()) {
            for (File file : f.listFiles()) {
                zipAutoBase(file, base, out);
            }/* w w  w .ja  va 2s .c o  m*/
        } else {
            String path = f.getPath().replace(base.getPath(), "");
            if (path.startsWith(System.getProperty("file.separator"))) {
                path = path.substring(1);
            }
            path = path.replace(System.getProperty("file.separator"), "/");
            FileInputStream fin = new FileInputStream(f);
            ZipEntry entry = new ZipEntry(path);
            out.putNextEntry(entry);
            byte[] buffer = new byte[8192];
            int bytes_read = 0;
            while ((bytes_read = fin.read(buffer)) != -1) {
                out.write(buffer, 0, bytes_read);
            }
            fin.close();
        }
    }
}

Related

  1. archiveFile(String relativePath, ZipOutputStream zos, File root)
  2. writeFolderEntry(ZipOutputStream zout, String relpath)
  3. zip(File current, String rootPath, ZipOutputStream zipStream, byte[] buffer)
  4. zip(File[] files, String baseDir, ZipOutputStream zos)
  5. zip(final File directory, final File base, final ZipOutputStream zipOutputStream)
  6. zipFile(ZipOutputStream out, File file, String dir)
  7. zipFile(ZipOutputStream out, File sourceFile)
  8. zipFile(ZipOutputStream out, String stripPath, File file, char pathSeparator)
  9. zipFile(ZipOutputStream zipOut, String path, File file)