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不是指的是整个文件吗 为什么不用压缩文件里面的一个文件是否结束判断呢
解决方案 »
- IBM中国研究院面试题
- 当收到输入窗口的"确定"按钮才更新数据库,"放弃"则不更新,请问调用该输入窗体的函数怎么获得输入窗口的选择结果?
- 想做一个抽签程序,思路应如何??
- 请问专家一个关于SocketTimedoutException的问题
- 大家好,为什么用jbuilder 开发,昨天还能编译的类,今天就死活不认了呢?
- 布署在tomcat中的代码想运行一个本地程序,怎么写?
- 兄弟们推荐一本学习jbuilder的书,最初级的!就是一步一个图的那种!
- 远程发送给server多个class文件,server怎么执行这些class?
- 请高人指导:java与图像处理。
- Jbuilder7.0 注册码?
- java中的多态问题
- 请教大家两个问题
public abstract int read()
throws IOException从输入流读取下一个数据字节。返回 0 到 255 范围内的 int 字节值。如果因已到达流末尾而没有可用的字节,则返回值 -1。在输入数据可用、检测到流的末尾或者抛出异常前,此方法一直阻塞。
子类必须提供此方法的一个实现。
返回:
下一个数据字节,如果到达流的末尾,则返回 -1。