读书人

Java Zip资料解压

发布时间: 2012-12-19 14:13:14 作者: rapoo

Java Zip文件解压

写完了流的解压,想到文件的解压,也写一个例子吧!

?

接下来的故事:

?

package com.lippeng.helloworld;import java.io.IOException;import java.io.InputStream;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;public class HelloWorld {    public static void main(String[] args) {String fFilePath = "C:\\abc.zip";InputStream inputStream = null;try {    ZipFile zipFile = new ZipFile(fFilePath);    ZipEntry entry = zipFile.getEntry("abc.txt");// 拿到压缩包中一个名叫abc.txt的文件    inputStream = zipFile.getInputStream(entry);    byte[] b = new byte[1];    int count = inputStream.read(b);    while (count != -1) {// 在这里做想做的事情System.out.println(b);count = inputStream.read(b);    }} catch (IOException e) {    e.printStackTrace();} finally {    try {if (inputStream != null) {    inputStream.close();}    } catch (IOException e) {e.printStackTrace();    }}    }}
?

读书人网 >编程

热点推荐