我在unix框上有一个.Z文件。有没有办法从java调用unix uncompress命令?
答案 0 :(得分:3)
我还需要解压缩.Z档案,通过互联网查看,但没有找到比我下面更好的答案。可以使用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();
这确实有效
答案 1 :(得分:0)
Runtime.exec("uncompress " + zFilePath);
<强>更新强>
根据文档,ProcessBuilder.start()
是首选。
ProcessBuilder pb = new ProcessBuilder("uncompress", zFilePath);
Process p = pb.start();
// p.waitFor();