Java Zip File List zipFiles(File file, JarOutputStream jos, String pathName)

Here you can find the source of zipFiles(File file, JarOutputStream jos, String pathName)

Description

zip Files

License

Open Source License

Declaration

private static void zipFiles(File file, JarOutputStream jos, String pathName) throws Exception 

Method Source Code


//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;

public class Main {
    private static int bufSize = 2048;

    private static void zipFiles(File file, JarOutputStream jos, String pathName) throws Exception {
        String fileName = pathName + file.getName();
        if (file.isDirectory()) {
            fileName = fileName + "/";
            jos.putNextEntry(new JarEntry(fileName));
            String fileNames[] = file.list();
            if (fileNames != null) {
                for (int i = 0; i < fileNames.length; i++) {
                    zipFiles(new File(file, fileNames[i]), jos, fileName);
                }//from w ww  .  j ava2s  . c  om
                jos.closeEntry();
            }
        } else {
            JarEntry jarEntry = new JarEntry(fileName);
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
            jos.putNextEntry(jarEntry);

            byte[] buf = new byte[bufSize];
            int len;
            while ((len = in.read(buf)) >= 0) {
                jos.write(buf, 0, len);
            }
            in.close();
            jos.closeEntry();
        }
    }
}

Related

  1. zip(String[] sourceFiles, String zipFile, String directory)
  2. zip(String[] srcFiles, String dstFile, String comment)
  3. zipFileList(List files, File destinationDir)
  4. zipFiles(ArrayList files, String destZipFile)
  5. zipFiles(Collection resFileList, File zipFile)
  6. zipFiles(File output, File root, List fileList)
  7. zipFiles(File rootDir, File currDir, ZipOutputStream zos)
  8. zipFiles(File[] dirList, ZipOutputStream zos)
  9. zipFiles(File[] listFiles2Zip, File output)