cant find close() method on Apache WorkbookFactory

依然范特西╮ 提交于 2019-12-20 05:43:10

问题


i read about Apache WorkbookFactory

the guide are saying to close workbook when done. "Workbook should be closed after use"

but i dont have a close method to close it.

how could it be closed ?

Workbook wb = WorkbookFactory.create(tempFile);
wb.close();

i'm working with Apache poi Maven, version 3.9

The method close() is undefined for the type Workbook   ...     line 423    Java Problem

Note 1: that in order to properly release resources the Workbook should be closed after use.

Note 2: also that loading from an InputStream requires more memory than loading from a File

i would like to use a file and not an input stream like this one sayes


回答1:


cant find close() method on Apache WorkbookFactory

You need to close the Workbook, not its factory.

Note 1: that in order to properly release resources the Workbook should be closed after use.

Correct.

Note 2: also that loading from an InputStream requires more memory than loading from a File

Untrue, unless the InputStream is a ByteArrayInputStream.




回答2:


Workbook.close() was implemented in poi 3.11 version.

You have to close your output stream after work with workbook is done and it was written.

From POI user guide:

Workbook wb = new XSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream("workbook.xlsx");
wb.write(fileOut);
fileOut.close();

Don't forget to close workbook as well:

wb.close();


来源:https://stackoverflow.com/questions/34282946/cant-find-close-method-on-apache-workbookfactory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!