Bug 56906 - While reading .docx(of more than 10mb) file with Apache POI its throwing OutOfMemory error
Summary: While reading .docx(of more than 10mb) file with Apache POI its throwing OutO...
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.10-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-01 11:14 UTC by Ajeet Singh
Modified: 2014-09-01 11:27 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ajeet Singh 2014-09-01 11:14:11 UTC
I am using apche POI-3.10, I have to read an sample.docx file and write its content to new sampleOutput.docx file.
However I have succeed to do the same but while reading file’s more than or equal to 10mb in size, XWPFDocument is not able to read the file, its throwing error “java.lang.OutOfMemoryError: Java heap space”

Following is the sample code for the reference, Request you to help me with any solution

try {                                        
FileInputStream  fis = new FileInputStream(“sample.docx”);
                XWPFDocument  document = new XWPFDocument(OPCPackage.open(inputFilePath));  // its throws error here with files of size >= 10 mb            
                OutputStream  outStream = new FileOutputStream(outputFilePath);     

                document. write(outStream);

}catch(Exception e){
                e.printStackTrace();
}
Comment 1 Nick Burch 2014-09-01 11:27:04 UTC
The default JVM heap size is very very small by modern standards. You need to increase that at JVM startup (-Xmx) to something more sensible before handling larger files