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){
FileInputStream in;
String text =
null
;
try
{
in =
new
FileInputStream(
new
File(file));
WordExtractor extractor =
null
;
extractor =
new
WordExtractor();
text = extractor.extractText(in);
}
catch
(FileNotFoundException e) {
e.printStackTrace();
}
catch
(Exception e) {
e.printStackTrace();
}
return
text;
}
}