0

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

Android
  • 360
  • 5
  • 15

2 Answers2

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

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:

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

Community
  • 1
  • 1
Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196
0

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();
Matt Pollock
  • 1,063
  • 10
  • 26