【问题标题】:Outofmemory exception while reading an excel file having more than 90k records读取超过 9 万条记录的 Excel 文件时出现内存不足异常
【发布时间】:2019-07-13 09:17:51
【问题描述】:

我想从 excel 中找到总行数。内存不足异常

         try {
                InputStream myxls = new FileInputStream("File path");

                workbook = new XSSFWorkbook(myxls);
                System.out.println(ele.productHierarchyText());
                XSSFSheet sheet = workbook.getSheet("Sheet Name");
                XSSFRow row = sheet.getRow(0);

                int colNum = row.getLastCellNum();
                System.out.println("Total Number of Columns in the excel is : " + colNum);

                rowNum = sheet.getLastRowNum() + 1;
                System.out.println("Total Number of Rows in the excel is : " + rowNum);
         }

【问题讨论】:

  • 为您用来解析的库添加链接和/或标签。

标签: java excel rowcount


【解决方案1】:

您的 JVM 似乎没有分配足够的内存。由于它同时读取 90k 条记录并试图将它们保存在堆内存中,因此它应该有足够的堆内存来容纳这些记录。

可以使用 -Xmx 标志增加堆内存。您需要确保为您的应用程序的堆和非堆分配足够的内存以避免内存不足错误。

更多详情可以查看https://outofmemoryerror.io/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 2014-06-17
    相关资源
    最近更新 更多