如何使用Java中的apache commons压缩库来压缩和解压缩目录?

时间:2013-05-25 10:12:49

标签: java compression apache-commons

我想压缩目录并使用apache commons压缩库解压缩,所以

我怎么能这样做?

感谢所有

1 个答案:

答案 0 :(得分:0)

如果你想压缩目录,可以选择

public static void createZip(String directoryPath, String zipPath) throws IOException {
        FileOutputStream fOut = null;
        BufferedOutputStream bOut = null;
        ZipArchiveOutputStream tOut = null;

        try {
            fOut = new FileOutputStream(new File(zipPath));
            bOut = new BufferedOutputStream(fOut);
            tOut = new ZipArchiveOutputStream(bOut);
            addFileToZip(tOut, directoryPath, "");
        } finally {
            tOut.finish();
            tOut.close();
            bOut.close();
            fOut.close();
        }

 }