我正在尝试读取 .doc 文件。这是我的代码:
import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class ReadDocFile {
public static void main(String[] args) {
File file = null;
WordExtractor extract = null;
try {
file = new File("c:\\New.doc");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
HWPFDocument document = new HWPFDocument(fis);
extract = new WordExtractor(document);
String[] fileData = extract.getParagraphText();
for (int i = 0; i < fileData.length; i++) {
if (fileData[i] != null) {
System.out.println(fileData[i]);
}
}
} catch (Exception exep) {
}
}
}
它在以下行给出红色错误:
extract = new WordExtractor(document);
错误是说, 对单词提取器的引用不明确 WordExtractor 中的构造函数 WordExtractor(DirectoryNode) 和 WordExtractor 中的构造函数 WordExtractor(HWPFDocument) 均匹配
帮我解决一下。
最佳答案
我遇到了同样的问题,我添加了 3.0 版本
http://www.findjar.com/jar/poi/poi/3.0-FINAL/poi-3.0-FINAL.jar.html
关于java - 对 WordExtractor 的引用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27690867/