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();
	    }
	}

    }
}
 

你可能感兴趣的:(java,C++,c,C#)