读取docx文件并尝试将其存储在字符串变量中 下面是我的代码
try {
File file = new File(fileName);
FileInputStream fileInputStream = new FileInputStream(file.getAbsolutePath());
XWPFDocument document = new XWPFDocument(fileInputStream);
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph para : paragraphs) {
System.out.println(para.getText());
docContent = para.getText();
}
fileInputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
它成功读取了内容,但没有将整个内容存储在字符串变量(docContent
)中,
答案 0 :(得分:2)
您尚未串联字符串docContent += para.getText();
,请使用+
进行串联