javaapache-poi

java.lang.OutOfMemoryError: Java heap space while reading excel with Apache POI


My file is 9MB and I got this error while loading workbook.

XSSFWorkbook workbook = new XSSFWorkbook(excelFilePath); 

this line causes to java.lang.OutOfMemoryError: Java heap space

How can I solve this?


Solution

  • I think default heap size is 128M

    You can increase this using the -Xmx argument to java

    e.g.

    java -Xmx512m myapp.java