您的位置:首页 > 编程语言 > Java开发

java读取zip文件和压缩zip文件

2012-08-28 16:34 357 查看
java读取名为T11.zip的文件,解压后再生成名为T22.zip的文件。

代码如下:

import java.io.*;
import java.util.zip.*;

public class ReadWriteZip {

public static void main(String[] args) throws Exception {
FileInputStream fi = new FileInputStream("/home/tom/test/T11.zip");
ZipInputStream zi = new ZipInputStream(fi);
FileOutputStream fo = new FileOutputStream("/home/tom/test/T22.zip");
ZipOutputStream zo = new ZipOutputStream(fo);
ZipEntry ze;
while ((ze = zi.getNextEntry()) != null) {
zo.putNextEntry(ze);
byte[] buffer = new byte[1024];
int len;
while ((len = zi.read(buffer)) > 0) {
zo.write(buffer, 0, len);
}
}
zi.closeEntry();
zo.closeEntry();
zi.close();
zo.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: