易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

Java选择题

选择题
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 虚拟机运行时数据区域 Runtime Data Areas

The Java virtual machine defines various runtime data areas that are used during execution of a program. Some of these data areas are created on Java virtual machine start-up and are destroyed only when the Java virtual machine exits. Other data areas are per thread. Per-thread data areas are create ......

Java内部类访问外部对象的方法

  Java编程时,为类DialogTry2添加关闭窗口事件,我在构造方法中采用事件适配器来实现:
    this.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent e){
          &nbs ......

Java类被加载时执行的顺序问题

public class Parent
{
    //1
    static int a =  1;
    //2
    static
    {
        a = 10;
        System.out.println("parent static c ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号