public static void unzip(String zipFile, String destpath)
throws IOException {
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
ZipEntry z = null; while ((z = zis.getNextEntry()) != null) {
if (z.isDirectory()) {
File f = new File(destpath + z.getName());
f.mkdirs();
} else {
String file = z.getName();
FileOutputStream fos = new FileOutputStream(destpath + file);
int tmp = -1;
while ((tmp = zis.read()) != -1) {
fos.write(tmp);
} zis.closeEntry();
fos.close();
}
}
}为什么是while ((tmp = zis.read()) != -1)   zis不是指的是整个文件吗  为什么不用压缩文件里面的一个文件是否结束判断呢

解决方案 »

  1.   

    看apiread
    public abstract int read()
                      throws IOException从输入流读取下一个数据字节。返回 0 到 255 范围内的 int 字节值。如果因已到达流末尾而没有可用的字节,则返回值 -1。在输入数据可用、检测到流的末尾或者抛出异常前,此方法一直阻塞。 
    子类必须提供此方法的一个实现。 
    返回:
    下一个数据字节,如果到达流的末尾,则返回 -1。 
      

  2.   

    API中的确是这么说的,看来ZipInputStream并不是看read的返回值来判断是否整个文件流的结尾,而是看getNextEntry的返回值是否为空来判断的,想想实际上也只能由普通的文件结尾来判断压缩包中的多个文件分割符号吧。