views:

49

answers:

1

Is there a simple way, either through the Java libraries or a third party library to zip an existing file in Java?

I am already familiar with the approach of creating a ZipOutputStream, adding ZipEntry objects to that, and then reading the data from a stream into the ZipOutputStream, I'm looking for a simpler way to zip up one File. Most likely this is going to be a recommendation for a third party compression library.

+4  A: 

The Apache Cayenne project has a pretty simple ZipUtil, you can check out the javadoc here:

http://cayenne.apache.org/doc20/api/cayenne/org/apache/cayenne/util/ZipUtil.html

Looking at the source it only has imports from the Java SDK so it should be easy to just drop into your application:

http://svn.apache.org/repos/asf/cayenne/main/branches/cayenne-jdk1.5-generics-unpublished/src/main/java/org/apache/cayenne/util/ZipUtil.java

rancidfishbreath
Thanks for the link to the code, not exactly what I am looking for, but that should be helpful.
James McMahon