Java 壓縮/ 解壓 .Z 文件


1.問題描述

公司項目有需要用 JAVA 解壓 .z文件. .z 是 unix 系統常見的壓縮文件. 

2.源碼

import com.chilkatsoft.CkUnixCompress;

import java.util.StringTokenizer;

/**
 * Created by zzy on 16/12/29.
 */
//import com.chilkatsoft.*;

public class ChilkatExample {
    

    static {
        try {
            System.load("/Users/zzy/IdeaProjects/dk_project/dk_qingdyinlian/qdyl_file/lib/libchilkat.jnilib");
        } catch (UnsatisfiedLinkError e) {
            System.err.println("Native code library failed to load.\n" + e);
            System.exit(1);
        }
    }

    public static void main(String argv[]) {

        String property = System.getProperty("java.library.path");
        StringTokenizer parser = new StringTokenizer(property, ";");
        while (parser.hasMoreTokens()) {
            System.err.println(parser.nextToken());
        }


        CkUnixCompress uc = new CkUnixCompress();

        boolean success;

        //  Any string unlocks the component for the 1st 30-days.
        success = uc.UnlockComponent("Anything for 30-day trial");
        if (success != true) {
            System.out.println(uc.lastErrorText());
            return;
        }
        String file = "/Users/zzy/Downloads/chrome-down/testzip/test/12.txt";

        success = uc.CompressFile(file, file+"hamlet.xml.Z");

        if (success != true) {
            System.out.println(uc.lastErrorText());
        } else {
            System.out.println("Success.");
        }


    }
}

工程目錄

我的運行結果

3 . com.chilkatsoft

這個包找了很久才找到,下載鏈接: chilkatsoft
注意:不同系統對應的不同的文件

(結束) 歡迎關注:農民阿姨


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM