I need to extract .tar.Z file using java [duplicate]

試著忘記壹切 提交于 2019-12-13 02:45:51

问题


Do anyone have coding in java to extract .tar.Z files.

Assume that i am having file called home.tar.Z I need extract this file using java code, can you give any sample code.

Thanks


回答1:


The .Z extension is not the gzip extension, it is from compress.

You can launch shell scripts from Java, I'd do it like that, since I don't know any compress library for Java. For tar/gz you could use Plexus Archiver or Apache Commons VFS.

See

  • How do I extract a tar file in Java?
  • How to Compress/Decompress tar.gz files in java

Sadly it doesn't seem that any libraries cover .Z files, so I think those links are unusable for you.

But take a look at:

  • How to make pipes work with Runtime.exec()?

This allows you to do everything with the shell commands which means you won't have to bother doing it from Java.




回答2:


It is obviously late to help the OP, but for posterity, Apache commons-compress does support *.Z.

For example

import org.apache.commons.compress.compressors.z.ZCompressorInputStream;

...

FileInputStream fin = new FileInputStream("/path/to/archive.something.Z");
BufferedInputStream in = new BufferedInputStream(fin);
ZCompressorInputStream zIn = new ZCompressorInputStream(in);

BufferedReader br = new BufferedReader(new InputStreamReader(zIn));

while (null != (content = br.readLine())) {
  System.out.println(content);
}
br.close();


来源:https://stackoverflow.com/questions/15039566/i-need-to-extract-tar-z-file-using-java

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