Reputation: 11
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;
}
Upvotes: 0
Views: 639
Reputation: 12838
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.
Upvotes: 1