How Android reads doc files

Source: Internet
Author: User
Tags root directory

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.