JAVA简单的zip文档 文件读取例子
package zipTest.com.test;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ZIPTest {
private static int BUF_SIZE = 1024*10;
public static void main(String[] args) {
try {
//加载zip文件
ZipInputStream zin = new ZipInputStream(new FileInputStream("D:/img.zip"));
ZipEntry entry = null;
String na = null;
while ((entry = zin.getNextEntry()) != null) {
//获取对象名称
na = entry.getName();
System.out.println(na);
//确定文件存放位置
File fs = new File("D:"+File.separator+"dddd"+File.separator+na);
//判断对象是是否是文件夹
if(entry.isDirectory()){
fs.mkdirs();
continue;
}
//保存文件
BufferedOutputStream fo = new BufferedOutputStream(new FileOutputStream(fs));
byte [] content=new byte[BUF_SIZE];
int len;
while((len=zin.read(content))!=-1){
fo.write(content,0,len);
fo.flush();
}
fo.close();
zin.closeEntry();
}
zin.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}