0

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;
}
2
  • It seems like you are reading a big file, what is the size of it? Commented Oct 13, 2016 at 9:22
  • @JakubJankowski size is 16 MB. I tried increasing JVM memory upto 2G but still see same issue. Commented Oct 13, 2016 at 17:39

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.