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;
    }
}
posted on 2012-04-18 16:27  轻盈  阅读(1852)  评论(0编辑  收藏  举报