Java基础-压缩解压

几种实现方案

#1.基于java.util.zip;

#2.使用zip4j

#3.使用org.apache.tools.ant

 

 

示例代码

测试代码

    <!-- Java zip > zip4j > apache ant -->

    /**

     * 方式1

     * -基于: java.util.zip

     * ---https://github.com/Blankj/AndroidUtilCode

     * ---https://github.com/SearchSunny/Android-zip-

     * summary:

     * ---#1.效率高,java.util.zip解压效率是zip4j的4倍

     * ---#2.支持.zip

     */

    public static void zipWithJava() {

        long startTime = System.currentTimeMillis();

        try {

            ZipUtils.unzipFile(zipFilePath, unzipFilePath);

        } catch (IOException e) {

            e.printStackTrace();

        }

        long endTime = System.currentTimeMillis();

        long costTime = endTime - startTime;

        System.out.print("Java zip: " + costTime + "ms" + "\n");

    }

 

    /**

     * 方式2

     * -基于: zip4j

     * ---https://github.com/ghost1372/Mzip-Android

     * ---http://www.lingala.net/zip4j/

     * summary:

     * ---#1.解压效率比较低;

     * ---#2.支持.zip .rar;

     */

    public static void zipZip4j() {

        long startTime = System.currentTimeMillis();

 

        try {

            ZipArchive.unzip(zipFilePath, unzipFilePath, "");

        } catch (Exception e) {

            e.printStackTrace();

        }

        long endTime = System.currentTimeMillis();

        long costTime = endTime - startTime;

        System.out.print("Zip4j: " + costTime + "ms" + "\n");

    }

 

    /**

     * 方式3

     * -基于: org.apache.tools.ant

     * ---http://ant.apache.org/bindownload.cgi

     * ---https://www.cnblogs.com/jecyhw/p/4531277.html

     * ---https://www.cnblogs.com/interdrp/p/6734033.html

     * summary:

     * ---#1.解压效率最低;

     * ---#2.支持.zip;

     */

    public static void zipApacheAnt() {

        long startTime = System.currentTimeMillis();

 

        try {

            AntZip.unzip(zipFilePath, unzipFilePath);

        } catch (Exception e) {

            e.printStackTrace();

        }

        long endTime = System.currentTimeMillis();

        long costTime = endTime - startTime;

        System.out.print("ApacheAnt: " + costTime + "ms" + "\n");

    }

Source:

https://github.com/zhengoogle/Java-Common/tree/master/ZipLibrary

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值