当我尝试使用apache poi 3.17读取doc文件的内容时出现以下错误:
java.lang.IllegalArgumentException: The document is really a OOXML file at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:123) at org.apache.poi.hwpf.HWPFDocument.(HWPFDocument.java:169) at project12.Home12.button1ActionPerformed(Home12.java:312) at project12.Home12.access$300(Home12.java:24) at project12.Home12$3.actionPerformed(Home12.java:113) at java.awt.Button.processActionEvent(Button.java:409) at java.awt.Button.processEvent(Button.java:377) at java.awt.Component.dispatchEventImpl(Component.java:4889) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
我已加入xmlbeans-2.6.0.jar
和dom4j-1.6.1.jar
,但问题仍然存在。
答案 0 :(得分:1)
当您尝试读取.doc文件而实际上是docx格式时,就会发生这种情况。
在这种情况下,请使用XWPFDocument
类而不是HWPFDocument
。
干杯! :)