Sarbjit Hanjra
Sarbjit Hanjra

Reputation: 33

Apache POI 3.16 - OutOfMemory Exception while reading 75K rows EXCEL (.xlsx) using XSSF

As per requirement, my application first need to read a Excel file which will around 75K-100K rows with 90 columns. But I got the following exception on line number 2 while XSSFWorkbook load the pkg/file

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.createChunk(Unknown Source)

I am using the following code to read excel file and currently 1 GB memory allocated to Heap and I am not even able to read 15K rows file.

1 OPCPackage pkg = OPCPackage.open("C:/Users/Admin/eclipse-workspace/HelloWorld/src/data.xlsx"); 2 XSSFWorkbook wb = new XSSFWorkbook(pkg);

or

//Read the spreadsheet that needs to be updated 1 FileInputStream inputFile = new FileInputStream("C:/Users/Admin/eclipse-workspace/HelloWorld/src/data.xlsx");
2 XSSFWorkbook wb = new XSSFWorkbook(inputFile);

Please let me know if there is any solution or if there is any other library or framework available for Java to read large Excel files.

Upvotes: 0

Views: 544

Answers (2)

Babak Badnava
Babak Badnava

Reputation: 41

you must use a streaming method for such huge files,

refer to this link for more details : here

Upvotes: 0

Amit Mahajan
Amit Mahajan

Reputation: 915

You can refer here: What are the Xms and Xmx parameters when starting JVMs? and set java memory arguments to avoid Out of memory errors.

Upvotes: 1

Related Questions