使用chilkat解压.Z(unix压缩格式)的压缩文件
1、当然是导包了
下载地1(官网):https://www.chilkatsoft.com/
下载地址2:http://download.csdn.net/download/fantasic_van/9957370
2、直接上代码
static {
try {
//System.loadLibrary("chilkat");
System.load("/usr/lib/libchilkat.so");
} catch (UnsatisfiedLinkError e) {
logger.info("Native code library failed to load.\n" + e);
System.exit(1);
}
}
这个静态代码块,需要在解压或压缩前执行,目的是引入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){
CkUnixCompress uc = new CkUnixCompress();
boolean success;
success = uc.UnlockComponent("Anything for 30-day trial");
if (success != true) {
logger.info(uc.lastErrorText());
return;
}
success = uc.CompressFile(filePath, destinationPath);
if (success != true) {
logger.info(uc.lastErrorText());
} else {
logger.info("Success.");
}
}
解压
public static void decompressFile(String filePath , String destinationPath){
CkUnixCompress uc = new CkUnixCompress();
boolean success;
success = uc.UnlockComponent("Anything for 30-day trial");
if (success != true) {
logger.info(uc.lastErrorText());
return;
}
success = uc.UncompressFile(filePath, destinationPath);
if (success != true) {
logger.info(uc.lastErrorText());
} else {
logger.info("Success.");
}
}
ps: 这个工具只有30天试用期,如果过期了,需要重新去下载新的版本,大牛也可以破解一下。
还没有评论,来说两句吧...