使用chilkat解压.Z(unix压缩格式)的压缩文件

布满荆棘的人生 2022-06-13 09:08 345阅读 0赞

1、当然是导包了

  1. 下载地1(官网):https://www.chilkatsoft.com/
  2. 下载地址2http://download.csdn.net/download/fantasic_van/9957370

2、直接上代码

  1. static {
  2. try {
  3. //System.loadLibrary("chilkat");
  4. System.load("/usr/lib/libchilkat.so");
  5. } catch (UnsatisfiedLinkError e) {
  6. logger.info("Native code library failed to load.\n" + e);
  7. System.exit(1);
  8. }
  9. }

这个静态代码块,需要在解压或压缩前执行,目的是引入chilkat动态库文件。
需要注意的问题(重点):

  • 载入库文件有两个函数,System.load 和 System.loadLibrary。
    当使用System.load时,需要输入文件的全路径,例如:System.load(“/tmp/test.so”);
    当使用System.loadlibrary时是在系统的library 的目录中需找复合条件的库文件,可以使用-Djava.library.path=[path]参数,来指定Java程序加载库文件的路径,或者将库文件(.so,.dll)复制到include的默认路径,Linux一般是/usr/lib目录下,当然你可以编辑/etc/ld.so.conf.d/下的文件,设定自己的库查找路径ldconfig -v|grep xxx看看有没有你的动态库。
    Linux还要注意,使用System.loadLibrary(name)方法其中参数内容与Windows有区别,Linux中的的库文件名为libname.so,Windows为name.dll。
  • 我在解决linux的问题中,用的就是System.load(“/tmp/test.so”) 绝对路径,这个方便快捷
  • 使用System.loadlibrary(“xxxx”)时,必须将xxxx.dll库文件放在java.library.path路径中,解决办法有多种,下面列出我的解决办法(windows系统)
    1) 将xxxx.dll放到C:\Windows\System32中即可
    2)使用eclipse配置
    这里写图片描述

3、解决了动态库文件的问题,则可以进行解压和压缩了

  • 压缩

    public static void compressFile(String filePath , String destinationPath){

    1. CkUnixCompress uc = new CkUnixCompress();
    2. boolean success;
    3. success = uc.UnlockComponent("Anything for 30-day trial");
    4. if (success != true) {
    5. logger.info(uc.lastErrorText());
    6. return;
    7. }
    8. success = uc.CompressFile(filePath, destinationPath);
    9. if (success != true) {
    10. logger.info(uc.lastErrorText());
    11. } else {
    12. logger.info("Success.");
    13. }
    14. }
  • 解压

    public static void decompressFile(String filePath , String destinationPath){

    1. CkUnixCompress uc = new CkUnixCompress();
    2. boolean success;
    3. success = uc.UnlockComponent("Anything for 30-day trial");
    4. if (success != true) {
    5. logger.info(uc.lastErrorText());
    6. return;
    7. }
    8. success = uc.UncompressFile(filePath, destinationPath);
    9. if (success != true) {
    10. logger.info(uc.lastErrorText());
    11. } else {
    12. logger.info("Success.");
    13. }
    14. }

ps: 这个工具只有30天试用期,如果过期了,需要重新去下载新的版本,大牛也可以破解一下。

发表评论

表情:
评论列表 (有 0 条评论,345人围观)

还没有评论,来说两句吧...

相关阅读

    相关 使用pandas读取压缩文件

    使用pandas读取压缩格式的文件 在Python的数据分析中,pandas是非常重要的库之一。在处理数据时,我们通常需要读取各种各样的数据格式,其中包括压缩格式的数据。本文