hi..
I'm trying to read a .docx file using apache poi api methods.. But i'm facing a few problems..

Can anyone suggest me the changes to be made in this code??

package apiole;

import java.io.*;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;

public class Apiole {
    public static void main(String[] args) throws IOException {
       File f = new File("D:\\vishal\\java_projects\\doc.docx");
       InputStream in = new FileInputStream(f);
       String test = extractText(in);
       System.out.print("text: "+test);
    }

    public static String extractText(InputStream in) {
        XWPFDocument doc = new XWPFDocument(in);
    XWPFWordExtractor ex = new XWPFWordExtractor(doc);
    String text = ex.getText();
    return text;
    }
}

Recommended Answers

All 4 Replies

What errors are you getting?

XWPFDocument doesn't exist.. Something like that..
I've included both scratchpad and ooxml archives in my project..

does the file exist?
run a check on your f variable.

yes, file exists..
I got it! I need to import org.apache.poi.xwpf.usermodel.XWPFDocument
XWPFDocument class is defined in this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.