错误信息:
读取docx文件时XWPFWordExtractor(OPCPackage)错误
Multiple markers at this line
- The constructor XWPFWordExtractor(OPCPackage) refers to the missing type XmlException
- The type org.apache.xmlbeans.XmlException cannot be resolved. It is indirectly referenced from
required .class files
错误信息The constructor XWPFWordExtractor(OPCPackage) refers to the missing type XmlException
原因:缺少xmlbeans包
源代码:
package com.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hwpf.HWPFDocument;
public class Test {
public void readDoc(String path) throws IOException {
File f = new File(path);
InputStream is = new FileInputStream(f);
HWPFDocument doc = new HWPFDocument(is);
System.out.println(doc.getDocumentText());
}
public static void main(String[] args) {
Test t = new Test();
try {
t.readDoc("C:/Users/Administrator/Desktop/test.doc");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}