81,091
社区成员
发帖
与我相关
我的任务
分享
public static void unZipFile(String dir,String zipfilename) throws ZipException, IOException{
log.debug("unzipfile:"+dir+File.separator+zipfilename);
File file = new File(dir+File.separator+zipfilename);//压缩文件
ZipFile zipFile = new ZipFile(file);//实例化ZipFile,每一个zip压缩文件都可以表示为一个ZipFile
//实例化一个Zip压缩文件的ZipInputStream对象,可以利用该类的getNextEntry()方法依次拿到每一个ZipEntry对象
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(file));
ZipEntry zipEntry = null;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
String fileName = zipEntry.getName();
File temp = new File(dir +File.separator+fileName);
if (! temp.getParentFile().exists())
temp.getParentFile().mkdirs();
OutputStream os = new FileOutputStream(temp);
//通过ZipFile的getInputStream方法拿到具体的ZipEntry的输入流
InputStream is = zipFile.getInputStream(zipEntry);
int len = 0;
while ((len = is.read()) != -1)
os.write(len);
os.close();
is.close();
}
zipInputStream.close();
zipFile.close();
log.debug("unzip file over:"+dir+File.separator+zipfilename);
}
Exception in thread "main" java.lang.IllegalArgumentException
at java.util.zip.ZipInputStream.getUTF8String(ZipInputStream.java:307)
at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:247)
at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:74)
at com.intelcube.olap.utils.IcoZipUtil.main(IcoZipUtil.java:123)
public static void main(String[] a) throws ZipException, IOException{
File file = new File("E:\\xiangywWork\\开发任务\\资料\\测试文件\\单价分析表.zip");//压缩文件
ZipFile zipFile = new ZipFile(file);//实例化ZipFile,每一个zip压缩文件都可以表示为一个ZipFile
//实例化一个Zip压缩文件的ZipInputStream对象,可以利用该类的getNextEntry()方法依次拿到每一个ZipEntry对象
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(file));
ZipEntry zipEntry = null;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
String fileName = zipEntry.getName();
File temp = new File("E:\\xiangywWork\\开发任务\\资料\\测试文件\\"+File.separator+fileName);
if (! temp.getParentFile().exists())
temp.getParentFile().mkdirs();
OutputStream os = new FileOutputStream(temp);
//通过ZipFile的getInputStream方法拿到具体的ZipEntry的输入流
InputStream is = zipFile.getInputStream(zipEntry);
int len = 0;
while ((len = is.read()) != -1)
os.write(len);
os.close();
is.close();
}
zipInputStream.close();
zipFile.close();
}