title: How to extract numbering and text from .docx file
body: <p>How do I extract numbering and text from a <code>.docx</code> file using Java and the Apache POI XWPF library?</p>
  
  <p>I am using the following code:</p>
  
  <pre><code>public static void readDocxFile() {
  
      try {
          File file = new File("C:\\test.docx");
          FileInputStream fis = new FileInputStream(file.getAbsolutePath());
          XWPFDocument document = new XWPFDocument(fis);
          List&lt;XWPFParagraph&gt; paragraphs = document.getParagraphs();
  
          for (XWPFParagraph para : paragraphs) {
              System.out.println(para.getText());
  
              fis.close();
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>My code is only extracting the text, like below:</p>
  
  <pre><code>CLIENT SERVICE SATISFACTION
  Client Feedback System
  Interlibrary Loans
  Shelf Tidiness
  Three Day Loans
  Materials Availability Survey
  Online help service
  </code></pre>
  
  <p>I need to extract the chapter number (numbering) with the text, like the following: </p>
  
  <pre><code>1    CLIENT SERVICE SATISFACTION
  1.1   Client Feedback System
  1.1.1 Interlibrary Loans
  1.1.2 Shelf Tidiness
  1.1.3 Three Day Loans
  1.2   Materials Availability Survey
  1.3   Online help service
  </code></pre>