How to Compress/Decompress tar.gz files in java

前端 未结 7 1086
粉色の甜心
粉色の甜心 2020-12-02 17:05

Can anyone show me the correct way to compress and decompress tar.gzip files in java i\'ve been searching but the most i can find is either zip or gzip(alone).

7条回答
  •  离开以前
    2020-12-02 17:25

    If you are planning to compress/decompress on Linux, you can call the shell command line to do that for you:

    Files.createDirectories(Paths.get(target));
    ProcessBuilder builder = new ProcessBuilder();
    builder.command("sh", "-c", String.format("tar xfz %s -C %s", tarGzPathLocation, target));
    builder.directory(new File("/tmp"));
    Process process = builder.start();
    int exitCode = process.waitFor();
    assert exitCode == 0;
    

提交回复
热议问题