Java调用linux zip打包路径问题

使用如下方式打zip包时,压缩包内的路径会包含完整的/path/to/xxx

ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("zip", "-r", "/path/to/xxx.zip", "/path/to/xxx").start();

使用directory切换一下目录用相对路径就好了

ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.directory(new File("/path/to/"));
processBuilder.command("zip", "-r", "xxx.zip", "xxx").start();

你可能感兴趣的:(java)