在Unix中使用java解压缩.Z文件

toe95027  于 2022-11-04  发布在  Unix
关注(0)|答案(2)|浏览(163)

我有一个.Z文件在unix上。有没有办法从java调用unix解压缩命令?

ncgqoxb0

ncgqoxb01#

我也面临着解压的需要。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();

Check this link
这真的有用

w1e3prcc

w1e3prcc2#

使用java.lang.Runtime.exec

Runtime.exec("uncompress " + zFilePath);

更新

根据文档,首选ProcessBuilder.start()

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

相关问题