I have a .Z file present on unix box. Is there any way to call unix uncompress command from java?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With