【发布时间】:2018-01-17 15:29:16
【问题描述】:
我在 SOAP Web 服务的 Web 方法中编写了以下代码。下面的代码是用来读取.xlsx文件的,但是代码会跳转到finally块,不会抛出任何异常。
FileInputStream fis = null;
try {
File excel = new File("Sample.xlsx");
fis = new FileInputStream(excel);
System.out.println("Can read: "+excel.canRead()); //true
System.out.println("Absolute path: "+excel.getAbsolutePath()); //returns correct file path
System.out.println("is File: "+excel.isFile()); //true
System.out.println("File exists: "+excel.exists()); //true
XSSFWorkbook book = new XSSFWorkbook(fis); //The control goes to the finally block
XSSFSheet headerDataSheet = book.getSheetAt(0);
........
}catch(Exception ex){
ex.printStackTrace();
}finally{
System.out.println("Cache Map DataSize---"+cacheMap.size());
.....
}
我使用了以下罐子。
axis.jar、commons-discovery-0.2.jar、commons-fileupload-1.3.2.jar、commons-io-1.3.2.jar、commons-logging.jar、commons-net-3.6.jar、jaxrpc.jar、 poi-3.8.jar
poi-ooxml-3.8.jar, poi-ooxml-schemas-3.8-beta5.jar
在 stackoverflow 上找到类似帖子后,我尝试更新 poi jar 版本,但即使这样也没有帮助。感谢您提供任何帮助/建议。
谢谢
【问题讨论】:
-
你可以尝试从soap上下文中临时导出你的方法并在main方法中测试它。看看是不是 POI 的问题。
-
尝试添加
catch (Error e),看看有没有被抓到 -
你为什么使用这么旧版本的 Apache POI?升级时会发生什么?
-
@RomanPuchkovskiy 而不是 Error 我尝试了 Throwable 所以 catch 表达式看起来像:catch(Throwable ex){ ex.printStackTrace(); } 但控制还是直接转到 finally 方法。
标签: java soap apache-poi