我想讀取一個大小爲50Mb的excel,並通過poi在java中包含各種表格,但問題是當我嘗試創建對象時,我在下面發佈的堆棧跟蹤的例外情況。對於出存儲器空間錯誤的我已經配置此用Apache POI打開電子表格時內存不足
-Xmx1024m -Duser.timezone=GMT0 already
下面
是其中我試圖讀取的excel拳頭,然後將其convrting成字節數組稍後將它作爲bytr流,其中i檢測它的快照擴展,它是的.xlsx類型的,因此momnet我嘗試創造我得到了下面的異常請告知如何從這個
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);
後來下面我正在進一步創建對象如下圖所示
克服對象 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 *********//
}
,我在創建上述workbookXlsx對象
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)
請指教是POI內部異常或堆空間一個
可能不是一個答案,但肯定是一個很好的開始[OutOfMemoryError:Java堆空間](http://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java -heap-space-error-64mb-heap?rq = 1) – Prudhvi
內存不足。 – bmargulies
我正在運行此參數-Xmx1024m -Duser.timezone = GMT0已經 –