0

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

Community
  • 1
  • 1
2Big2BeSmall
  • 1,348
  • 3
  • 20
  • 40

2 Answers2

10

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();
dlopatin
  • 3,752
  • 1
  • 17
  • 18
2

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.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    could you tell me how to close this Workbook ? Workbook wb = WorkbookFactory.create(tempFile); – 2Big2BeSmall Dec 15 '15 at 07:12
  • 1
    InputStreams really do need more memory than files, [as explained here](http://poi.apache.org/spreadsheet/quick-guide.html#FileInputStream), as with a File data can be left on disk and accessed as needed while with a Stream you have to buffer the whole lot into memory for the required random access – Gagravarr Dec 15 '15 at 09:28