I am using Apache poi 3.8 for reading xls file, but i got exception:
java.io.IOException: Unable to read entire header; 0 bytes read; expected 512 bytes
at org.apache.poi.poifs.storage.HeaderBlock.alertShortRead(HeaderBlock.java:226)
at org.apache.poi.poifs.storage.HeaderBlock.readFirst512(HeaderBlock.java:207)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
used code sample:
FileInputStream myInput = new FileInputStream(excelFilePathWithExtension);
logger.debug("FileInputStream::"+myInput);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
logger.debug("POIFSFileSystem::"+myFileSystem);
Workbook workbook = WorkbookFactory.create(myFileSystem);
please help me?
If we take a look at the HeaderBlocks class, we can see these blocks :
The constructor you used will read the first 512 bytes of your inputstream then call a private constructor.
And the
readFirst512method throw an exception if there is not enough bytes to read.Also, the POI’s document say that a POI file system structure starts starts with a header block of 512 bytes.
So… It seems that your file is not big enough for POI.