poi版本是poi-3.17
具体报错如下:
java.lang.IllegalArgumentException: The document is really a UNKNOWN file
at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:123)
at org.apache.poi.hwpf.extractor.WordExtractor.(WordExtractor.java:51)
at ETDemo.readWord(ETDemo.java:24)
at ETDemo.main(ETDemo.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
代码如下:
String text = "";
File file = new File(filePath);
//2003
if(file.getName().endsWith(".doc")){
try {
FileInputStream stream =null;
stream=new FileInputStream(file);
WordExtractor word = new WordExtractor(stream);