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不是指的是整个文件吗 为什么不用压缩文件里面的一个文件是否结束判断呢
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不是指的是整个文件吗 为什么不用压缩文件里面的一个文件是否结束判断呢
public abstract int read()
throws IOException从输入流读取下一个数据字节。返回 0 到 255 范围内的 int 字节值。如果因已到达流末尾而没有可用的字节,则返回值 -1。在输入数据可用、检测到流的末尾或者抛出异常前,此方法一直阻塞。
子类必须提供此方法的一个实现。
返回:
下一个数据字节,如果到达流的末尾,则返回 -1。