【问题标题】:Read a .Z file (unix compresses file) in Java在 Java 中读取 .Z 文件(unix 压缩文件)
【发布时间】:2010-08-13 01:02:01
【问题描述】:
上述文件扩展名在http://kb.iu.edu/data/abck.html 进行了解释。我想使用 java api 来读取 Z 文件的内容。 ZipFile api 或 GZIPInputStream 似乎都不起作用。我可以使用 ZipFile api 打开普通的 .zip 文件。
ZipFile zf = new ZipFile("CR93H2.Z");
Enumeration entries = zf.entries();
补充一点,.Z 文件在 winrar 中可以正常打开。
有没有人知道解决办法。
谢谢
【问题讨论】:
标签:
java
file
unix
compression
【解决方案1】:
你可以使用compress-j2me:
% git clone https://github.com/igorgatis/compress-j2me.git
% cd compress-j2me/src/lzc-test
% ant -q
% cd build/cmd
% echo "testdonkeyballs" | compress | java com.googlecode.compress_j2me.lzc.Main -d
testdonkeyballs
对于维护的替代方案,请尝试Apache Commons-Compress。
【解决方案2】:
我已经使用UncompressInputStream.java 成功读取压缩文件。我还没有验证逻辑是否正确,但它似乎有效。
FileInputStream fis = new FileInputStream( new File( "thefile.cfg.Z" ) );
InputStream is = new UncompressInputStream( new BufferedInputStream( fis ) );
BufferedReader reader = new BufferedReader(new InputStreamReader( is ) );
String line = null;
while ( ( line = reader.readLine() ) != null )
{
System.out.println( "line = " + line );
}