gpt4 book ai didi

java apache poi - xwpfparagraph 到字符串转换

转载 作者:行者123 更新时间:2023-11-30 02:05:50 25 4
gpt4 key购买 nike

读取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)中,

最佳答案

You have not concatenate the string docContent += para.getText(); use + for concatenation

关于java apache poi - xwpfparagraph 到字符串转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51399716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com