my code: content = "1111"; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content.getBytes()); String realPathFile = DIR_IN + "empty.doc"; POIFSFileSystem poifsFileSystem = new POIFSFileSystem(new FileInputStream(realPathFile)); poifsFileSystem.createOrUpdateDocument(byteArrayInputStream, "WordDocument"); HWPFDocument hwpfDocument = new HWPFDocument(poifsFileSystem); hwpfDocument.write(new FileOutputStream(DIR_OUT + outFileName)); hwpfDocument.close(); poifsFileSystem.close(); byteArrayInputStream.close(); console exception: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11 at org.apache.poi.util.LittleEndian.getShort(LittleEndian.java:253) at org.apache.poi.hwpf.model.types.FibBaseAbstractType.fillFields(FibBaseAbstractType.java:95) at org.apache.poi.hwpf.model.FibBase.<init>(FibBase.java:43) at org.apache.poi.hwpf.HWPFDocumentCore.getEncryptionInfo(HWPFDocumentCore.java:255) at org.apache.poi.hwpf.HWPFDocumentCore.getDocumentEntryBytes(HWPFDocumentCore.java:327) at org.apache.poi.hwpf.HWPFDocumentCore.<init>(HWPFDocumentCore.java:169) at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:193) at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:177) at com.snoopy.poi.HTML2doc.main(HTML2doc.java:55)
Seems the document is corrupt or at least confuses Apache POI, can you attach it? Does it open in Microsoft Word without errors being shown?