使用apache的ZipOutputStream,产生死循环,生成了超大的压缩包,求解原因?
代码如下:public static void getZip(String baseDir,String objFileName){
if(folderObject.exists()){
List fileList = getSubFiles(new File(baseDir));
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(objFileName));
ZipEntry ze = null;
byte[] buf = new byte[1024];
int readLen = 0;
for(int i = 0; i < fileList.size();i++){
File f = (File)fileList.get(i);
ze = new ZipEntry(getAbsFileName(baseDir,f));
ze.setSize(f.length());
ze.setTime(f.lastModified());
zos.putNextEntry(ze);
InputStream is = new BufferedInputStream(new FileInputStream(f));
while((readLen = is.read(buf,0,1024)) != -1){
zos.write(buf,0,readLen);
}
is.close();
}
zos.close();
}
}
private static List getSubFiles(File baseDir){
List ret = new ArrayList();
File[] tmp = baseDir.listFiles();
for(int i = 0; i < tmp.length; i++){
if(tmp[i].isFile()){
ret.add(tmp[i]);
}
}
return ret;
}
private static String getAbsFileName(String baseDir, File realFileName){
File real = realFileName;
File base = new File(baseDir);
String ret = real.getName();
while(true){
real = real.getParentFile();
if(real == null) break;
if(real.equals(base)) break;
else ret = real.getName();
}
return ret;
} apache file string list byte --------------------编程问答--------------------
--------------------编程问答-------------------- 这个问题不是每次都出现,只是偶尔。
while((readLen = is.read(buf,0,1024)) != -1){
zos.write(buf,0,readLen);
}
is.close();//应该是zos先关闭
}
zos.close();
zos.close(); //这个操作是不是要在遍历完所有文件列表才能关闭啊?也就是for循环语句结束后。 --------------------编程问答-------------------- 自己顶一下! --------------------编程问答-------------------- 查看下是否将压缩文件存放在了源文件(待压缩文件)目录下? --------------------编程问答-------------------- 每次生成的压缩文件也会临时存储在待压缩文件目录下,下载完后,会全部删除,不知道是否会影响?
什么情况下压缩文件删除不成功呢?
补充:Java , Web 开发