Java无需解压直接读取Zip文件里的文件内容
package com.wicresoft.jpo;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
public class ReadZipUtil {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
readZipFile("D:\\test\\test.zip");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void readZipFile(String file) throws Exception {
ZipFile zf = new ZipFile(file);
InputStream in = new BufferedInputStream(new FileInputStream(file));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry ze;
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
// System.out.print("directory - " + ze.getName() + " : "
// + ze.getSize() + " bytes");
// System.out.println();
} else {
System.err.println("file - " + ze.getName() + " : "
+ ze.getSize() + " bytes");
long size = ze.getSize();
if (size > 0) {
BufferedReader br = new BufferedReader(
new InputStreamReader(zf.getInputStream(ze)));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
System.out.println();
}
}
zin.closeEntry();
}
}
相关文档:
选择题
3阅读一下程序:
Boolean a=false;
Boolean b=true;
Boolean c=(a&b)&&(!b);
Int result=b==false?1:2;
这段程序执行完后,c与result的值是(D)。
A c=false; result=1; B. c=true;result=2;
C.c=true;result=1 D. c=false; result=2
6.下述声明中哪种可防 ......
[转帖]Java学习之路:不走弯路,就是捷径
2007-04-11 16:10
在ChinaITLAB导师制辅导中,笔者发现问得最多的问题莫过于"如何学习编程?Java该如何学习?"。类似的问题回答多了,难免会感觉厌烦,就萌生了写下本文的想法。到时候再有人问起类似的问题,我可以告诉他(她),请你去看看《Java学习之路》。拜读过台湾蔡学镛先 ......
在CSDN中看到了个有关java技巧的帖子,觉得非常有用,可以避免开发过程中产生的一些低级的错误,帖子本身已经进行了总结,我挑出了其中一些个人觉得平时开发过程中有用的部分,再加上自己在工作中学到的技巧,整理在本文中,并随着时间实时更新
1、写好注释。输入参数、输出类型、方法功能,把这三点描 ......
本文转自:http://cyp-034.blog.163.com/blog/static/2823190520074691849380/
stream
代表的是任何有能力产出数据的数据源,或是任何有能力接收数据的接收源。在Java的IO中,所有的stream(包括Inputstream和
Out stream)都包括两种类型:
(1)字节流
表示以字节为单位从stream中读取或往stream中写入 ......