i am trying to read an excel that is of 50Mb in size and containg various sheets in it through poi in java but the issue is that when i try to creat the object i got the exception of which the stack trace I have posted below. for out of memory space error i have configured this
-Xmx1024m -Duser.timezone=GMT0 already
below is the snapshot in which i am trying to read the excel fist and then convrting it into byte array later on passing it as bytr stream where i detect it extension and it is of .xlsx type so the momnet i try to creat the object i got the below exception please advise how to overcome from this
String fileName = "C:\\abc\\xret.xlsx";
FileInputStream fis = new FileInputStream(fileName);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] bFile = new byte[(int) fileName.length()];
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum);
}
} catch (IOException ex) {
ex.printStackTrace();
}
byte[] bytes = bos.toByteArray();
processExcelObjects( bytes);
later on below i am creating the objects further as shown below
byteArrayInputStream = new ByteArrayInputStream(bytes);
if (byteArrayInputStream.available() != -1 )
{
if (filename.lastIndexOf("."))).equalsIgnoreCase(".xlsx") )
{
XSSFWorkbook workbookXlsx = new XSSFWorkbook();
//**** got the exception ********//
workbookXlsx = new XSSFWorkbook(byteArrayInputStream); // ****** on this line I got the exception *********//
}
the exception that i got while creating the above workbookXlsx object is
org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
Caused by: java.lang.OutOfMemoryError: Java heap space
at org.apache.xmlbeans.impl.store.Cur$CurLoadContext.attr(Cur.java:3039)
at org.apache.xmlbeans.impl.store.Cur$CurLoadContext.attr(Cur.java:3060)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
please advise is it poi internal exception or heap space one