gpt4 book ai didi

java.lang.OutOfMemory错误: Java heap space for large excel file

转载 作者:行者123 更新时间:2023-11-30 06:04:58 24 4
gpt4 key购买 nike

我正在使用 Apache POI 读取 Excel 文件。我的文件大约有 100MB,我在加载工作簿时遇到了 java.lang.OutOfMemoryError: Java heap

XSSFWorkbook workbook = new XSSFWorkbook(excelFilePath);

我的电脑 RAM 是 8GB,所以它不能使用太大的 -Xmx。所以我的问题是如何处理这个错误?

编辑

我的数据示例(我的数据约为 1087490 行):

enter image description here

最佳答案

首先 - 您必须确保您的文件在该工具明确定义的限制范围内 - 请参阅 here .

除此之外,对于较大的文件来说内存不足似乎是一个相当常见的问题,一种解决方案是“手动”处理 XML 数据:

If memory footprint is an issue, then for XSSF, you can get at the underlying XML data, and process it yourself. This is intended for intermediate developers who are willing to learn a little bit of low level structure of .xlsx files, and who are happy processing XML in java. Its relatively simple to use, but requires a basic understanding of the file structure. The advantage provided is that you can read a XLSX file with a relatively small memory footprint.

(引自 here )

关于java.lang.OutOfMemory错误: Java heap space for large excel file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47883448/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com