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
注意:不同系统对应的不同的文件