title: Java: Apache POI: Can I get clean text from MS Word (.doc) files?
body: <p>The strings I'm (programmatically) getting from MS Word files when using Apache POI are not the same text I can look at when I open the files with MS Word.</p>
  
  <p>When using the following code:</p>
  
  <pre><code>File someFile = new File("some\\path\\MSWFile.doc");
  InputStream inputStrm = new FileInputStream(someFile);
  HWPFDocument wordDoc = new HWPFDocument(inputStrm);
  System.out.println(wordDoc.getText());
  </code></pre>
  
  <p>the output is a single line with many 'invalid' characters (yes, the 'boxes'), and many unwanted strings, like "<code>FORMTEXT</code>", "<code>HYPERLINK \l "_Toc##########"</code>" ('#' being numeric digits), "<code>PAGEREF _Toc########## \h 4</code>", etc.</p>
  
  <p>The following code "fixes" the single-line problem, but maintains all the invalid characters and unwanted text:</p>
  
  <pre><code>File someFile = new File("some\\path\\MSWFile.doc");
  InputStream inputStrm = new FileInputStream(someFile);
  WordExtractor wordExtractor = new WordExtractor(inputStrm);
  for(String paragraph:wordExtractor.getParagraphText()){
    System.out.println(paragraph);
  }
  </code></pre>
  
  <hr>
  
  <p>I don't know if I'm using the wrong method for extracting the text, but that's what I've come up with when looking at <a href="http://poi.apache.org/hwpf/quick-guide.html" rel="noreferrer">POI's quick-guide</a>. If I am, what is the correct approach?</p>
  
  <p>If that output is correct, is there a standard way for getting rid of the unwanted text, or will I have to write a filter of my own?</p>