java 无法在 Apache WorkbookFactory 上找到 close() 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34282946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cant find close() method on Apache WorkbookFactory
提问by 2Big2BeSmall
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
我正在使用 Apache poi Maven,版本 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.
注1:为了正确释放资源,Workbook 使用后应关闭。
Note 2: also that loading from an InputStream requires more memory than loading from a File
注意 2:从 InputStream 加载比从 File 加载需要更多内存
i would like to use a file and not an input stream like this onesayes
我想用类似文件,而不是一个输入流,这一个sayes
回答by dlopatin
Workbook.close()
was implemented in poi 3.11 version.
Workbook.close()
在 poi 3.11 版本中实现。
You have to close your output stream after work with workbook is done and it was written.
在完成工作簿的工作并写入后,您必须关闭输出流。
From POI user guide:
来自POI 用户指南:
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();
回答by user207421
cant find close() method on Apache WorkbookFactory
无法在 Apache WorkbookFactory 上找到 close() 方法
You need to close the Workbook
, not its factory.
您需要关闭Workbook
,而不是它的工厂。
Note 1: that in order to properly release resources the Workbook should be closed after use.
注1:为了正确释放资源,Workbook 使用后应关闭。
Correct.
正确的。
Note 2: also that loading from an
InputStream
requires more memory than loading from aFile
注意 2:从一个
InputStream
加载比从一个加载需要更多的内存File
Untrue, unless the InputStream
is a ByteArrayInputStream
.
不真实,除非InputStream
是ByteArrayInputStream
。