Android ZipOutputStream Write zipFile(File resFile, ZipOutputStream zipout, String rootpath)

Here you can find the source of zipFile(File resFile, ZipOutputStream zipout, String rootpath)

Description

zip File

Declaration

private static void zipFile(File resFile, ZipOutputStream zipout,
        String rootpath) throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
import org.apache.http.protocol.HTTP;
import java.io.BufferedInputStream;

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 final int BUFF_SIZE = 1024 * 1024;

    private static void zipFile(File resFile, ZipOutputStream zipout,
            String rootpath) throws FileNotFoundException, IOException {
        rootpath = rootpath// w w w.j a  va 2  s.  c  o m
                + (rootpath.trim().length() == 0 ? "" : File.separator)
                + resFile.getName();
        rootpath = new String(rootpath.getBytes("8859_1"), HTTP.UTF_8);
        BufferedInputStream in = null;
        try {
            if (resFile.isDirectory()) {
                File[] fileList = resFile.listFiles();
                for (File file : fileList) {
                    zipFile(file, zipout, rootpath);
                }
            } else {
                byte buffer[] = new byte[BUFF_SIZE];
                in = new BufferedInputStream(new FileInputStream(resFile),
                        BUFF_SIZE);
                zipout.putNextEntry(new ZipEntry(rootpath));
                int realLength;
                while ((realLength = in.read(buffer)) != -1) {
                    zipout.write(buffer, 0, realLength);
                }
                in.close();
                zipout.flush();
                zipout.closeEntry();
            }
        } finally {
            if (in != null)
                in.close();
            // if (zipout != null); 
            // zipout.close(); 
        }
    }
}

Related

  1. zipFile(File resFile, ZipOutputStream zipout, String rootpath)
  2. zipFile(File resFile, ZipOutputStream zipout, String rootpath)
  3. zipFile(File resFile, ZipOutputStream zipout, String rootpath)
  4. zipFile(File resFile, ZipOutputStream zipout, String rootpath)
  5. zipFile(File resFile, ZipOutputStream zipout, String rootpath)
  6. zipFile(File resFile, ZipOutputStream zipout, String rootpath)
  7. zipFile(ZipOutputStream out, File file)
  8. zipFile(ZipOutputStream out, File file)
  9. ZipFiles(ZipOutputStream out, String path, File... srcFiles)