Read a .Z file (unix compresses file) in Java

白昼怎懂夜的黑 提交于 2019-11-27 08:35:52

问题


The said file extension is explained here at http://kb.iu.edu/data/abck.html. I want to use a java api to read the contents of a Z file. Neither the ZipFile api or the GZIPInputStream seem to work. I can use the ZipFile api to open normal .zip files.

ZipFile zf = new ZipFile("CR93H2.Z");
Enumeration entries = zf.entries();

To add, the said .Z file opens up fine in winrar.

Does anyone know about the solution to it.

Thanks


回答1:


You can use compress-j2me:

% svn checkout --quiet http://compress-j2me.googlecode.com/svn/trunk/ compj2me
% cd compj2me/src/lzc-test
% ant -q
% cd build/cmd
% echo "testdonkeyballs" | compress | java com.googlecode.compress_j2me.lzc.Main -d
testdonkeyballs



回答2:


I've had success reading compressed files with UncompressInputStream.java. I haven't verified if the logic is correct, but it seems to work.

    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 );
    }


来源:https://stackoverflow.com/questions/3473179/read-a-z-file-unix-compresses-file-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!