我想通过 ZipFile 类来读取一个ZIP 但是试了几种方法都不能够进行读取,所以想提出来想问问大家错在哪里?public class formatTest{

public static void main(String[] args)throws IOException{
ZipFile zf = new ZipFile("D:\\333\\111.zip");
ZipEntry ze2;
Enumeration e = zf.entries();

while(e.hasMoreElements()){
ze2 = (ZipEntry)e.nextElement();
System.out.println("File: " + ze2);
// CheckedInputStream cis = new CheckedInputStream(zf.getInputStream(ze2), new CRC32()); //注释的3句代码都是另一种读取
// ZipInputStream zis = new ZipInputStream(cis);
// BufferedInputStream bis = new BufferedInputStream(zis);
BufferedReader bis = new BufferedReader(new InputStreamReader(zf.getInputStream(ze2)));
int i;
while((i = bis.read()) != -1){
System.out.write(i);
}
}
}
}

解决方案 »

  1.   

    能把Exception贴出来吗?
    个人认为你应该用字节流啊,而不应该用字符流啊!
      

  2.   

    回复楼上的,没有Exception,单单就无法读出而已
      

  3.   

    参考例子
    http://topic.csdn.net/u/20080708/19/1ca6881f-1736-4f2f-8554-0a12853472ae.html
      

  4.   

    测试是可以读出来的你的程序应该无法编译吧? 捕捉异常就可以了。
     public static void main(String[] args)
        {        ZipFile zf;
            try
            {
                zf = new ZipFile("D:\\111.zip");            ZipEntry ze2;
                Enumeration e = zf.entries();            while (e.hasMoreElements())
                {
                    ze2 = (ZipEntry) e.nextElement();
                    System.out.println("File: " + ze2);
                    BufferedReader bis;                bis = new BufferedReader(new InputStreamReader(
                        zf.getInputStream(ze2)));
                    int i;
                    while ((i = bis.read()) != -1)
                    {
                        System.out.write(i);
                    }            }
            }
            catch (Exception ex)
            {
                //to do yourself
            }    }