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);
}这玩意是不是不能解压 多个execel文件压缩的zip
我解析其他文件压缩的zip没问题多个execel文件压缩的zip,解析就异常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)
有人知道原因吗excelupzip

解决方案 »

  1.   

    有执行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();
    }
      

  2.   

    异常在这一行
     while ((zipEntry = zipInputStream.getNextEntry()) != null) {其他文件压缩的都可以解,excel压缩的就报错
      

  3.   

    应该是文件编码不是utf8引起的