我试图用Java读取Docx文件。
但是由于行号16中的“构造函数XWPFDocument(FileInputStream)未定义”和行号18中的“类型不匹配:无法从XWPFParagraph []转换为列表”,我收到了错误消息。
下面是我的代码。
二手罐子: org.apache.poi.xwpf.usermodel.XWPFDocument; org.apache.poi.xwpf.usermodel.XWPFParagraph;
有人可以告诉我为什么我要得到这个,请告诉我如何解决吗?
谢谢!
package com.readindDocx;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
public class ReadingDocument {
public static void main(String[] args) {
try {
File file = new File("D:/SampleWordFile.docx");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
XWPFDocument document = new XWPFDocument(fis);
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph para : paragraphs) {
System.out.println(para.getText());
}
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}