java中提供了对压缩格式的数据流的读写。它们封装到现成的IO 类中,以提供压缩功能。下面我们开始java中压缩文件的使用。

目录导航:

  1. 关于压缩的简要说明
  2. GZIP压缩文件的使用
  3. ZIP压缩文件的使用
  4. GZIP与ZIP压缩的比较
  5. 友情链接

关于压缩的简要说明

一、 Java中有着压缩的类:

  • CheckedInputStream                                     GetCheckSum()为任何InputStream 产生校验和(不仅是解压)
  • CheckedOutputStream                                   GetCheckSum()为任何OutputStream 产生校验和(不仅是解压)
  • DeflaterOutputStream                                    用于压缩类的基础类
  • ZipOutputStream                                            一个DeflaterOutputStream,将数据压缩成Zip 文件格式
  • GZIPOutputStream                                         一个DeflaterOutputStream,将数据压缩成GZIP 文件格式
  • InflaterInputStream                                        用于解压类的基础类
  • ZipInputStream                                              一个DeflaterInputStream,解压用Zip 文件格式保存的数据
  • GZIPInputStream                                           一个DeflaterInputStream,解压用GZIP 文件格式保存的数据

二、 压缩库的一些说明:

  • 压缩类库是按字节方式而不是字符方式处理的,它们属于InputStream和OutputStream继承层次结构的一部分

三、 ZIP压缩的使用注意:

  • 对于要加入压缩档的每一个文件,都必须调用putNextEntry(),并将其传递给一个ZipEntry 对象。
  • ZipEntry 对象包含了一个功能全面的接口,利用它可以获取和设置Zip 文件内那个特定的Entry(入口)上能够接受的所有数据:名字、压缩后和压缩前的长度、日期、CRC 校验和、额外字段的数据、注释、压缩方法以及它是否一个目录入口等等。
  • 尽管CheckedInputStream 和CheckedOutputStream 同时提供了对Adler32 和CRC32 校验和的支持,但是ZipEntry 只支持CRC 的接口
  • 为解压文件,ZipInputStream 提供了一个getNextEntry()方法,能在有的前提下返回下一个ZipEntry
  • 可以用ZipFile 对象读取文件。该对象有一个entries()方法,可以为ZipEntry 返回一个Enumeration(枚举)。

GZIP压缩文件的使用

我们通过一个简单的程序用例来展开今天压缩类的使用讲解 ,程序结构如下

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQIAAAExCAIAAAAYwzsEAAAgAElEQVR4nO2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/Y9vb41ll4wdPKL585p8Bf2TVR055jTPAIPMiO0BjazTyII4krmLQAK+DMA2UM4K6sv7KKhtnP7H/y2d++PxDVv32N/+HM8Cg8iIj65Cy44rd9QC8GcI0OPD6f92cPY5V4j588uiKZ09OfZlVHzPmPzgDDCYvMoIrDeBEQB6EaXBo4uhd455jFasGK194ilUv93+eM8Dg8iIzf/cFtymCEwGREKbBm/8ImhDmNyGcUawavLLwRUZ9mF9QyDjuCIPKi4z8FADS13mJzN5ngRCEQJgGnx6amd8ZySpWDT5Xfsyqfz9u8jAtC/ZBhEOYBv4RL0lPP88qVg3e+H4Mq/7lL/9zyBaikQcxzh9gAdEQpsEX+//6h6+eZpWPAn/7+RuPPD3ncVa9NHH+EC4F2VCBA6RDmAY6nU4lGJ1OJ/Z6ATIgTAMAGApAAwAADQAANAAAmkQNIBYZ8DjkaQCxyIDHIUwD741FRu+zAEiDMA28NxYZNCAZwjSAWGRgKCBMA4hFBoYCwjTwklhkTMwxM28sLn0y4L0QpoHXxCLbwaTJ5EufDHgvhGngLbHI3FfYZwMB3QGvgTANvCUWmdsfNCAZwjTwmlhkbBJYZFOESZ8MeC+EaeAlsciYmGPW2QCTPhnwXgjTwEtjkRnALog8CNPAa2KRXQAakAdhGnhRLDIvoAF5EKYBxCIDQwFhGgDAUAAaAABoAACgAQDQoAEA0KABANCgAQDQoAEA0DT9/wH5PBx4PIwUXgAAAABJRU5ErkJggg==" alt="" />

一、 我们创建一个GzipCompress类,用于GZIP压缩类的测试:首先是压缩文件方法compress():

// 压缩文件
private static void compress() throws Exception {
BufferedReader in = new BufferedReader(new FileReader(("compress/test.txt")));
BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("uncompress/test.gz")));
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
in.close();
out.close();
}

二、 我们创建GZIP的解压缩方法:uncompress()

// 解压缩文件
private static void uncompress() throws Exception {
BufferedReader in = new BufferedReader(
new InputStreamReader(new GZIPInputStream(new FileInputStream("uncompress/test.gz"))));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
in.close();
}

三、 在Main方法运行,得到如下结果:

  • 控制台打印:  Hello World.
  • 在uncompress文件夹下生成test.gz文件

ZIP压缩文件的使用

一、 我们创建一个ZipCompress类,用于GZIP压缩类的测试:

首先是压缩文件方法compress():压缩huhx.png,test2.txt, test3.txt, test4.txt文件

private final static String[] resources = new String[] { "huhx.png", "test2.txt", "test3.txt", "test4.txt" };

// 压缩文件
private static void compress() throws Exception {
FileOutputStream f = new FileOutputStream("uncompress/test.zip");
CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32());
ZipOutputStream zos = new ZipOutputStream(csum);
BufferedOutputStream out = new BufferedOutputStream(zos);
zos.setComment("A test of java zipping");
ZipEntry entry = null; for (String resource : resources) {
System.out.println("writing file: " + resource);
BufferedReader in = new BufferedReader(new FileReader("compress/" + resource));
entry = new ZipEntry(resource);
entry.setComment(resource + " comments");
zos.putNextEntry(entry);
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
in.close();
out.flush();
}
out.close();
System.out.println("checksum: " + csum.getChecksum().getValue());
}

二、 我们创建ZIP的解压缩方法:uncompress1()

// 解压缩文件
private static void uncompress1() throws Exception {
FileInputStream fi = new FileInputStream("uncompress/test.zip");
CheckedInputStream csum = new CheckedInputStream(fi, new Adler32());
ZipInputStream in2 = new ZipInputStream(csum);
BufferedInputStream bis = new BufferedInputStream(in2); ZipEntry ze;
while ((ze = in2.getNextEntry()) != null) {
System.out.println("reading file: " + ze.getName());
}
System.out.println("checksum: " + csum.getChecksum().getValue());
bis.close();
}

三、 我们创建ZIP的解压缩另外一种方法:uncompress2()

// 解压缩文件
private static void uncompress2() throws Exception {
ZipFile zf = new ZipFile("uncompress/test.zip");
Enumeration<?> e = zf.entries();
while (e.hasMoreElements()) {
ZipEntry entry = (ZipEntry) e.nextElement();
System.out.println("File: " + entry.getComment());
}
zf.close();
}

四、 运行compress()和uncompress1()方法,得到结果如下:

aaarticlea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FguLs03LePXjG1bgeGOwz3sQz39cIyNyQNhvsCDPdxDPd5b6CWBOvlwHDnS2G4Ex413ItrDgz3nDMM9+zScL/ZB2cY7jDcFR413Nk+lMtguMNwl1tiKMOdfVJeScR6wnD/FjDcgcG4CYbhDloYN8EAtIAEA98gwcA3SDDwDRIMfIMEA98gwcA3VoJX+7HHA5kUqidH3+Z46ldp+HVdi2d+gkAitpT0WMvebv0IjKwuS/rSEfoh8/2kD272Rs4Z6smaNgf6ai1WightBsnJFEzzSle0tkttnkJRle0Evn4l5Vww371zJPjoA0La23ZOISbpZNdNbbGcvCWYGfDr8n391eymff/RIy5LQ1gf+q+bueEtkF0pzy3ThiuiIZvmDS+MFGcO+bassNF1WAXLLzeb7/+CNcH0BKdOefFv0R2jprZWTmYJlvuzon+SrctDQ1ndIH7sLiVYnwPdSDDfpGqaT3E1noTrv7Rd0qeKnXcR6zLB9LsXzXfvbG6a7iVqSeJsPabe8azfkV/dEQaLlje8XTi7HCbBeNQTXAVVHh/PdOCv9MfFdun4+HREoiX4DfPdO28l2DDfzQTHaJqmvB/6WIKFausJtt50KPpmZqmL5TU1o/iaFRv7iq3wY31w0R8cYwHNQNdMba2cvB9FfkOimd0zHYnXnZmc4AujCHMOdD3BRiyqj9jrg1siT7a7LWfriCmfUyTHQn6T7qcSnPkPRnt8jz8rA1qTsutyMvk1rZCyVbObXVPjaxfpl7XWt0hn/nvfpXGwPAe69s7zXimxdNM0L+qkzL0uDqbMd4arW+LT+vxP8EQD+AYJBr5BgoFvkGDgGyQY+AYJBr75A9cSSOlBmVO2AAAAAElFTkSuQmCC" alt="" />

五、 运行compress()和uncompress2()方法,得到结果如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO4AAACZCAIAAACnq5EMAAAJ4klEQVR4nO2d3YGEIAyErYuCqMdqbMZiuAcFAyT8rLiH2fme7lg3xjgingO3OABUsPx3AgCMAVIGSvhcyptdzLo/t/0H+QTsVtrvvppjsyfyOYLTBMZuDyQG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AKkDJQAKQMl/AGAmmyly/N8+QAAAABJRU5ErkJggg==" alt="" />

GZIP与ZIP压缩的比较

  • GZIP: 如果只有单个数据流需要压缩(而不是一系列不同的数据),那么它就可能是最适当选择。
  • ZIP:   它可以方便地保存多个文件。甚至有一个独立的类来简化对Zip 文件的读操作

友情链接

java基础---->Zip压缩的使用的更多相关文章

  1. java基础---->Zip压缩的使用(转)

    java中提供了对压缩格式的数据流的读写.它们封装到现成的IO 类中,以提供压缩功能.下面我们开始java中压缩文件的使用. 目录导航: 关于压缩的简要说明 GZIP压缩文件的使用 ZIP压缩文件的使 ...

  2. Java 的zip压缩和解压缩

    Java 的zip压缩和解压缩 好久没有来这写东西了,今天中秋节,有个东西想拿出来分享,一来是工作中遇到的问题,一来是和csdn问候一下,下面就分享一个Java中的zip压缩技术,代码实现比较简单,代 ...

  3. 用java实现zip压缩

    本来是写到spaces live上的,可是代码的显示效果确实不怎么好看.在javaeye上试了试代码显示的顺眼多了. 今天写了个用java压缩的功能,可以实现对文件和目录的压缩. 由于java.uti ...

  4. Java实现zip压缩多个文件下载

    为了更好的演示,首先创建一个文件实体FileBean,包含了文件路径和文件名称: package com.javaweb.entity; import java.io.Serializable; /* ...

  5. Java操作zip压缩和解压缩文件工具类

    需要用到ant.jar(这里使用的是ant-1.6.5.jar) import java.io.File; import java.io.FileInputStream; import java.io ...

  6. java.util.zip压缩打包文件总结二: ZIP解压技术

    一.简述 解压技术和压缩技术正好相反,解压技术要用到的类:由ZipInputStream通过read方法对数据解压,同时需要通过CheckedInputStream设置冗余校验码,如: Checked ...

  7. java.util.zip压缩打包文件总结一:压缩文件及文件下面的文件夹

    一.简述 zip用于压缩和解压文件.使用到的类有:ZipEntry  ZipOutputStream 二.具体实现代码 package com.joyplus.test; import java.io ...

  8. JAVA实现zip压缩需要注意的问题

    近来对院社二维码平台进行2.0升级改造.于昨日踩到一个巨坑.特此记录... 需求源于院社编辑在批量下载二维码的时候,系统后台需要对所要下载的二维码进行重命名和zip打包压缩. 系统测试的时候发现:首次 ...

  9. Java实现zip压缩文件的解压

    需求描述: 前段时间写了一篇博客<Java实现对文本文件MD5加密并ftp传送到远程主机目录>,实现了一部分的业务需求.然而有些业务可能不止传送一个文件,有时候客户需要传多个文件,原有系统 ...

随机推荐

  1. 验证url的正则

    一. '/@(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()& ...

  2. (4.19)sql server中的事务模式(隐式事务,显式事务,自动提交事务)

    (4.19)sql server中的事务模式(隐式事务,显式事务,自动提交事务) 1.概念:隐式事务,显式事务,自动提交事务 2.操作:如何设置事务模式 3.存储过程中的事务 XACT_ABORT 1 ...

  3. cordic算法的verilog实现及modelsim仿真

    1. 算法介绍 CORDIC(Coordinate Rotation Digital Computer)算法即坐标旋转数字计算方法,是J.D.Volder1于1959年首次提出,主要用于三角函数.双曲 ...

  4. (转)在GitHub多个帐号上添加SSH公钥

    GitHub后台可以添加多个SSH Keys,但是同一个SSH Keys只能在添加在一个帐号上(添加时提示“Key is already in use”).理由很容易想到,SSH公钥使用时相当于用户名 ...

  5. 网络协议TCP、Http、webservice、socket区别

    网络协议TCP.Http.webservice.socket区别 http 和 webservice 都是基于TCP/IP协议的应用层协议 webservice是基于http的soap协议传输数据 w ...

  6. cocos代码研究(18)Widget子类Slider学习笔记

    理论基础 滑动条控件. 代码实践 实例: // Create the slider Slider* slider = Slider::create(); slider->loadBarTextu ...

  7. VS2010/MFC编程入门之前言

    鸡啄米的C++编程入门系列给大家讲了C++的编程入门知识,大家对C++语言在语法和设计思想上应该有了一定的了解了.但是教程中讲的例子只是一个个简单的例程,并没有可视化窗口.鸡啄米在这套VS2010/M ...

  8. STM32F105 USB管脚Vbus的处理

    源:STM32F105 USB管脚Vbus的处理 对于STM32F105/107来说,为了监测USB的连接问题,程序默认是通过Vbus管脚进行检查的.但是Vbus管脚和UART1的TXD复用,导致我们 ...

  9. Web安全之BurpSuite抓取HTTPS请求

    出现了问题,第一步要干什么呢? 当然是要去官方网站去找FAQ和help,先来练习一下英语 https://portswigger.net/burp/help/proxy_options_install ...

  10. 20145329 《网络对抗技术》MS08_067远程漏洞攻击

    MS08_067远程漏洞攻击:shell 实现攻击的前提是:攻击机和靶机在同一个网段下,首先将kali的ip改为与winxp的ip一样,二者能ping通 两台虚拟机: kali ip:192.168. ...