可能的重复:
你如何用枪压缩文件并保留 .gz 文件?
我使用以下命令解压缩文件:
gunzip -f test.TGZ
Run Code Online (Sandbox Code Playgroud)
这给了我 test.tar 文件,但我丢失了 test.TGZ 文件。有没有办法保留原始文件?
编辑和更新:我通过 Java 程序调用解压缩命令。TGZ 文件至少包含 1 个图像文件、1 个文本文件和 1 个视频文件。
Java方法:执行命令
private static InputStream executeCommand(String command, File workingDir)
throws Exception {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(command, null, workingDir);
int exitValue = -1;
try {
exitValue = process.waitFor();
} catch (InterruptedException ignore) {
}
if (exitValue != 0) {
InputStream errStream = process.getErrorStream();
String errMessage = null;
if (errStream.available() > 0) {
byte[] errOutput = new …Run Code Online (Sandbox Code Playgroud)