1. zip

1.1. zip

1.2. java zip

  • ZipOutputStream

1.2.1. 压缩多个文件

public void zipFolder(String sourceFileFolder, String zipFilePath) throws Exception {
    FileOutputStream fos = new FileOutputStream(zipFilePath);
    ZipOutputStream zipOut = new ZipOutputStream(fos);
    for (File fileToZip : new File(sourceFileFolder).listFiles()) {
        FileInputStream fis = new FileInputStream(fileToZip);
        ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
        zipOut.putNextEntry(zipEntry);

        byte[] bytes = new byte[1024];
        int length;
        while ((length = fis.read(bytes)) >= 0) {
            zipOut.write(bytes, 0, length);
        }
        fis.close();
    }
    zipOut.close();
    fos.close();
}

1.3. Apache Commons Compress

  • ZipArchiveOutputStream

1.4. References

results matching ""

    No results matching ""