资源泄漏:使用 Apache.POI XSSFWorkbook 时永远不会关闭工作簿警告 [英] Resource leak: workbook is never closed warning when using Apache.POI XSSFWorkbook

查看:104
本文介绍了资源泄漏:使用 Apache.POI XSSFWorkbook 时永远不会关闭工作簿警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我使用 Apache POI 将 Excel 文件解析到我的数据库.为此,我正在初始化一个 XSSFWorkbook 如下:

So, I using Apache POI in order to parse an Excel file to my Database. For this I am initializing an XSSFWorkbook as follows:

XSSFWorkbook workbook = new XSSFWorkbook(fIP);

然后我继续我的方法.workbook.close() 不能用作事后关闭工作簿的方法.关于如何在任务完成后让垃圾收集处理工作簿的任何想法?

Then I proceed with my method. workbook.close() is not available as a method to close the workbook afterwards. Any ideas of how can I let garbage collection take the workbook after the task is finished?

推荐答案

我遇到了这个问题,但它毫无意义.最后,我将问题追溯到我的 IDE (netbeans) 正在选择没有关闭"方法的早期版本的 POI 库 (v3.8).因此,请检查您的类路径并查找不同版本的 POI 库的重复导入.

I had this issue, and it was making little sense. In the end I tracked the issue down to my IDE (netbeans) was picking up an earlier version of the POI libraries (v3.8) which didn't have the "close" method. So check your class path and look for duplicate imports of different versions of the POI libraries.

这篇关于资源泄漏:使用 Apache.POI XSSFWorkbook 时永远不会关闭工作簿警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆