最近项目需要用到这个功能,请大牛指导。

推荐图书

  • Android 2高级编程(第2版)
  • Google Android SDK开发范例大全(第2版)
  • 疯狂Android讲义


1个回答

package com.word.read;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.textmining.text.extraction.WordExtractor;

import Android.app.Activity;
import Android.os.Bundle;
import Android.os.Environment;
import Android.widget.TextView;

public class WordReader extends Activity {
    /** Called when the activity is first created. */

    private TextView text;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        text = (TextView) findViewById(R.id.text);

        String str = readWord(Environment.getExternalStorageDirectory().getAbsolutePath() + "/baojinggong.doc");
        text.setText(str.trim().replace("\r", ""));
    }

    public String readWord(String file){
        //创建输入流用来<a title="读取doc文件" href="http://www.android-study.com/pingtaikaifa/38.html">读取doc文件</a>
        FileInputStream in;
        String text = null;
        try {
            in = new FileInputStream(new File(file));
            WordExtractor extractor = null;
            //创建WordExtractor
            extractor = new WordExtractor();
            //进行提取对doc文件
            text = extractor.extractText(in);
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return text;
    }
}