处理xlsx文件后,Java Unzip退出

时间:2017-01-25 22:42:24

标签: java xlsx unzip

我解压缩包含各种文件的目录。解压缩实用程序到达第一个Excel(xlsx)文件后,它会解压缩excel文件,然后退出而不处理剩余的文件。我做错了什么?

解压缩代码为:

byte[] buffer = new byte[1024];

try{

    //create output directory is not exists
    File folder = new File(outputFolder);
    if(!folder.exists()){
        folder.mkdir();
    }

    //get the zip file content
    ZipInputStream zis = zipFile;
    //get the zipped file list entry
    ZipEntry ze = zis.getNextEntry();

    while(ze!=null && !ze.getName().contains("__MACOSX")){

        if (ze.isDirectory()) {
            String folderPath = outputFolder + "/" + ze.getName();
            File subFolder = new File(folderPath);
            subFolder.mkdir();
        }
        else {

            String fileName = ze.getName();
            File newFile = new File(outputFolder + File.separator + fileName);

            System.out.println("file unzipped : " + newFile.getAbsoluteFile());

            //create folders
             new File(newFile.getParent()).mkdirs();

            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.close();
        }
        ze = zis.getNextEntry();
    }

    zis.closeEntry();
    zis.close();

    System.out.println("Done");

}catch(IOException ex){
    ex.printStackTrace();
}

0 个答案:

没有答案