我正在尝试读取.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