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

有帮助吗?

解决方案 2

Using java.lang.Runtime.exec:

Runtime.exec("uncompress " + zFilePath);

UPDATE

Accoridng to the documentation, ProcessBuilder.start() is preferred.

ProcessBuilder pb = new ProcessBuilder("uncompress", zFilePath);
Process p = pb.start();
// p.waitFor();

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top