Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncompress .Z file in unix using java

I have a .Z file present on unix box. Is there any way to call unix uncompress command from java?

like image 511
Shitu Avatar asked Mar 28 '14 11:03

Shitu


People also ask

How do I read a .Z file in UNIX?

Unfortunately, you cannot read compressed files the way you do normal files. You must first expand, or uncompress, the files. How you do that depends on the program used to compress the file in the first place. Replace filename with the name of the file you wish to expand.

What are .Z files in UNIX?

http://www.gnu.org/software/gzip/gzip.html Uncompress *.Z files. Files with a *. Z extension have been compressed by the UNIX "compress" program. Those files can be handled with the Unix "uncompress" program, or programs such as the PC and Mac utilities described below. UNIX.


1 Answers

I also faced the need to decompress .Z archives, looked through internet but have found no better answer than mine below. One can use Apache Commons Compress

FileInputStream fin = new FileInputStream("archive.tar.Z");
BufferedInputStream in = new BufferedInputStream(fin);
FileOutputStream out = new FileOutputStream("archive.tar");
ZCompressorInputStream zIn = new ZCompressorInputStream(in);
final byte[] buffer = new byte[buffersize];
int n = 0;
while (-1 != (n = zIn.read(buffer))) {
   out.write(buffer, 0, n);
}
out.close();
zIn.close();

Check this link

This really works

like image 111
Marian Avatar answered Sep 28 '22 09:09

Marian