Reading MS Word 2007 using Java
<p>I am trying to read a Microsoft word file through Java. I have included all the .jar files from Apache poi-3.8-beta1 to my classpath. However, when I try running this, I get the following exception:</p>

<pre><code>org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
        at org.apache.poi.poifs.storage.HeaderBlock.&lt;init&gt;(HeaderBlock.java:131)
        at org.apache.poi.poifs.storage.HeaderBlock.&lt;init&gt;(HeaderBlock.java:104)
        at org.apache.poi.poifs.filesystem.POIFSFileSystem.&lt;init&gt;(POIFSFileSystem.java:138)
        at readingmsword07.Main.main(Main.java:27)
</code></pre>

<p>Following is my code:</p>

<pre><code>import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xwpf.usermodel.XWPFDocument;


public class Main {


    public static void main(String[] args) {
        try {
            FileInputStream fis = new FileInputStream("C:\\TrialDoc.docx");
            POIFSFileSystem fileSystem = new POIFSFileSystem(fis);            
            org.apache.poi.xwpf.extractor.XWPFWordExtractor oleTextExtractor =
            new XWPFWordExtractor(new XWPFDocument(fis));
            System.out.print(oleTextExtractor.getText());            
        } catch (Exception e) {
                e.printStackTrace();
        }
    }

}
</code></pre>

<p>I am using the XWPFWordExtractor since I am trying to read a 2007 word document but for some reason I am unable to figure out the right POI that deals with this.</p>

<p>Any help is much appreciated. Thanks in advance!</p>

<p>~ Woods</p>
