Reading doc files on Android requires a third-party Jar pack Tm-extractors-0.4.jar, and the reading process is simple
As with normal file flow operations, write a simple example below:
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; The public class Wordreader extends activity {/** called the ' when the ' is the ' activity ' is the ' the '.
T
@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) {//Create input stream read doc file FileInputStream in;
String text = null;
try {in = new FileInputStream (new file); Wordextractor Extractor = NULL;
Create Wordextractor extractor = new Wordextractor ();
Extract text = Extractor.extracttext (in) for DOC file;
catch (FileNotFoundException e) {e.printstacktrace ();
catch (Exception e) {e.printstacktrace ();
} return text; }
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/
Code on these, it looks like file flow operation, just add a jar package, doc file in the simulator SD card root directory, after the operation of the following effect:
Currently in the process of optimization, this method can only read plain text files, if there are pictures in the file can not be displayed.
This article comes from CSDN blog: http://blog.csdn.net/huweilong1030/archive/2011/03/12/6242666.aspx