我写了一段代码解压ZIP文件,在windows环境下测试没有问题,但部署到UNIX环境下后,去发现压缩后几十K的文件可以正常解压,但压缩完后900多K的文件却无法解压,也无异常提示,只是在要路后发现zList.hasMoreElements()总是为false,也即Enumeration zList = zipFile.getEntries()根本没有获得压缩包里的文件,但在在windows下则正常,真弄不清楚怎么回事了,有谁遇到过这种情况吗?给个提示好吗?谢谢了~
public void zipToFiles(String dir , String filename) throws IOException{
System.out.println(dir + filename);
try{
ZipFile zipFile = new ZipFile(dir + filename);
Enumeration zList = zipFile.getEntries();
ZipEntry zipEntry = null;
byte[] buf = new byte[1024];
while(zList.hasMoreElements()){
zipEntry = (ZipEntry) zList.nextElement();
if (zipEntry.isDirectory()) {
System.out.println("Dir: " + zipEntry.getName() + " skipped..");
continue;
}

System.out.println("Extracting: " + zipEntry.getName() + "\t"+ zipEntry.getSize() + "\t" + zipEntry.getCompressedSize());

OutputStream os = new BufferedOutputStream(new FileOutputStream(
getRealFileName(dir, zipEntry.getName())));
InputStream is = new BufferedInputStream(zipFile.getInputStream(zipEntry));
int readLen = 0;
while ((readLen = is.read(buf, 0, 1024)) != -1) {
os.write(buf, 0, readLen);
}
is.close();
os.close();
System.out.println("Extracted: " + zipEntry.getName());
}
zipFile.close();
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}