用Java打开和阅读Word文档

时间:2014-02-22 15:36:26

标签: java apache-poi

我正在尝试使用Netbeans在JTextArea中打开和阅读Word文件。

import java.io.*;

import org.apache.poi.hwpf.HWPFDocument;

import org.apache.poi.hwpf.extractor.WordExtractor;

public class ReadDocFile {
    public static void main(String[] args) {
        File file = null;
        WordExtractor extractor = null;

        try {
            file = new File("c:\\New.doc");
            FileInputStream fis = new FileInputStream(file.getAbsolutePath());
            HWPFDocument document = new HWPFDocument(fis);
            extractor = new WordExtractor(document);
            String[] fileData = extractor.getParagraphText();
            for (int i = 0; i < fileData.length; i++) {
                if (fileData[i] != null)
                    System.out.println(fileData[i]);
            }
        } catch (Exception exep) {
        }
    }
}

我收到以下错误:

cannot find symbol : HWPFDocument((mypackgename).fileinputstream )

由于这个原因,我无法打开文件。有没有理由不这样做?

0 个答案:

没有答案