Apachi POI读取xssf工作簿,无异常结束,不读取文件

时间:2021-04-11 19:09:56

I am new to Apache POI. I am trying to reading xlsx file using xssf workbook. Its not reading some files and not throwing exception, its directly going to finally block. How to find out the exact root cause. Here's the line am using. Thanks in advance.

我是Apache POI的新手。我正在尝试使用xssf工作簿阅读xlsx文件。它没有读取一些文件而不是抛出异常,它直接进入最终阻止。如何找出确切的根本原因。这是我正在使用的线。提前致谢。

FileInputStream inputStream = new FileInputStream(file);

    try {
                Iterator<org.apache.poi.ss.usermodel.Row> rowIterator = null;


                    org.apache.poi.xssf.usermodel.XSSFWorkbook xlsxbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook(inputStream);
                    sheet = xlsxbook.getSheetAt(0);
    }
    catch (Exception e) {
                logger.log(Level.WARNING, "", e);
            } finally {
                try {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                } catch (Exception ioe) {
                    System.out.println(ioe);
                }
            }

1 个解决方案

#1


1  

Its hard to be certain from so little code, but "directly going to finally block" sounds a lot like throwing an exception. If you add the below code before the finally block, does anything get printed?

很难从这么少的代码确定,但“直接进入最终阻止”听起来很像抛出异常。如果在finally块之前添加以下代码,是否会打印任何内容?

catch (Throwable t){
   t.printStackTrace();
}

#1


1  

Its hard to be certain from so little code, but "directly going to finally block" sounds a lot like throwing an exception. If you add the below code before the finally block, does anything get printed?

很难从这么少的代码确定,但“直接进入最终阻止”听起来很像抛出异常。如果在finally块之前添加以下代码,是否会打印任何内容?

catch (Throwable t){
   t.printStackTrace();
}