Is there a way in Java to compress or combine a group of files that will preserve file permissions and file ownerships? I have tried JarOuputStream and ZipOutputStream and neither seem to work.

Tim Rohaly

Java has built-in support for compression in the java.util.zip and java.util.jar packages. These packages provide implementations of several standard and widely used compression utilities such as Zip, GZip, and Jar. However, none of these utilities supports preserving permission and ownership - no matter what programming language is used. In other words, there is no such thing as a Zip file which contains permission or ownership information.

If you need your archive to contain this meta information, you will need to use a scheme which explicitly preserves permission and ownership, such as the tar utility found on Unix. (Note that the standard implementation of tar doesn't do compression - it just does archiving. You can however GZip your tar archive to reduce its size.)

Because Java has no built-in support for examining or setting file permissions or ownership, any Java implementation of tar must use the JNI in order to preserve this information. There are several Java implementations of tar available, both free and commercial. I don't know of one that properly preserves this information.