0
votes

I am getting java.lang.OutOfMemoryError: Java heap space while reading Excel file into java bean using XLSReader

Here is the code snippet.

public static <T> List<T> parseExcelFileToBeans(final File xlsFile,
                                                                      final File jxlsConfigFile)
        throws Exception {
    final XLSReader xlsReader = ReaderBuilder.buildFromXML(jxlsConfigFile);
    final List<T> result = new ArrayList<>();
    final Map<String, Object> beans = new HashMap<>();
    beans.put("result", result);
    try (InputStream inputStream = new BufferedInputStream(new FileInputStream(xlsFile))) {
        xlsReader.read(inputStream, beans);
    }
    return result;
}
1
It seems like you are reading a big file, what is the size of it? - Jakub Jankowski
@JakubJankowski size is 16 MB. I tried increasing JVM memory upto 2G but still see same issue. - anup

1 Answers

1
votes

XLSReader tends to read all the data in memory.

So you if your file is big you will quickly run out of memory.

Depending on the size of the file you can increase the memory of your JVM by using the -Xms and -Xmx paramters.

If the file is really big I believe you need to change the strategy of reading the excel file. Link.