2

Reading the docx file and try to stored in string variable below is my code

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();
        }

its Read the content successfully, but its not stored the entire content in string variable (docContent),

Prabu
  • 3,550
  • 9
  • 44
  • 85

1 Answers1

2

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

Saurabh Yadav
  • 3,303
  • 1
  • 10
  • 20