开发者

Simple way to zip an existing file in Java?

开发者 https://www.devze.com 2023-01-08 06:43 出处:网络
Is there a simple way, either through the Java libraries or a third party library to zip an existing file in 开发者_运维知识库Java?

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消