I would actually stop using an external process, and switch to using Java code. Apache Commons Compress has a class TarArchiveOutputStream which works similar to ZipOutputStream. Wrap a GZIPOutputStream in it, and simply add entries recursively using File.listFiles():
I've added that parameter
path because in a recursive call, you need to append the folder to it. This is the only way I've found to maintain the full path of the Tar entries. For example, the following could be a recursive call chain:
tarFolder(out, new File("/usr/local/myfolder/abcd"), ""); -- to tar the
/usr/local/myfolder/abcd folder.
tarFolder(out, subFolder, "efgh"); -- to tar sub folder
efgh where
subFolder represents this sub folder.
tarFolder(out, subFolder, "efgh/ijkl"); -- to tar sub folder
ijkl of folder
efgh where
subFolder represents this sub folder.
pseudo code: tarFile(out, file, "efgh/ijkl/file.ext"); -- to tar file
file.ext inside folder
ijkl] where [tt]file represents this file.
If you continue with Runtime.exec or ProcessBuilder,
you should have read
When Runtime.exec() won't first.