public static void zip(String srcPath, String zipPath, String zipFileName) throws Exception {
        if (TextUtils.isEmpty(srcPath) || TextUtils.isEmpty(zipPath) || TextUtils.isEmpty(zipFileName)) {
            throw new NullPointerException();
        }
        CheckedOutputStream cos = null;
        ZipOutputStream zos = null;
        try {
            File srcFile = new File(srcPath);

            if (srcFile.isDirectory() && zipPath.contains(srcPath)) {
                throw new IllegalStateException(String.format("zipPath %s must not be the child directory of srcPath %s", zipPath, srcPath));
            }

            File zipDir = new File(zipPath);
            if (!zipDir.exists() || !zipDir.isDirectory()) {
                zipDir.mkdirs();
            }

            String zipFilePath = zipPath + File.separator + zipFileName;
            File zipFile = new File(zipFilePath);
            if (zipFile.exists()) {
                SecurityManager securityManager = new SecurityManager();
                securityManager.checkDelete(zipFilePath);
                zipFile.delete();
            }

            cos = new CheckedOutputStream(new FileOutputStream(zipFile), new CRC32());
            zos = new ZipOutputStream(cos);

            String srcRootDir = srcPath;
            if (srcFile.isFile()) {
                int index = srcPath.lastIndexOf(File.separator);
                if (index != -1) {
                    srcRootDir = srcPath.substring(0, index);
                }
            }
            zip(srcRootDir, srcFile, zos);
            zos.flush();
        } catch (Exception e) {
            throw e;
        } finally {
            try {
                if (zos != null) {
                    zos.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
Created by stuart on 2017/7/14.
https://raw.githubusercontent.com/Tornaco/DataMigration/master/app/src/main/java/org/newstand/datamigration/utils/ZipUtils.java
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/ZipUtils.java