Shi*_*itu 5 java unix compression
我在unix框上有一个.Z文件.有没有办法从java调用unix uncompress命令?
小智 5
我还需要解压缩 .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();
这确实有效
Runtime.exec("uncompress " + zFilePath);
更新
根据文档,ProcessBuilder.start()首选。
ProcessBuilder pb = new ProcessBuilder("uncompress", zFilePath);
Process p = pb.start();
// p.waitFor();
| 归档时间: | 
 | 
| 查看次数: | 1830 次 | 
| 最近记录: |