有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java解压在处理xlsx文件后退出

我正在解压缩一个包含各种文件的目录。解压实用程序到达第一个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) 个答案