如何阅读.doc文件?

时间:2011-06-27 06:38:55

标签: android

我的 sdcard 上保存了.doc个文件。我需要阅读.doc文件的内容并将其显示在TextView

有人可以告诉我怎么做吗?

1 个答案:

答案 0 :(得分:0)

抱歉我的错误。你需要这样做。

public void onCreate(Bundle b) {
    super.onCreate(b);
    setContentView(R.layout.main);
    String extPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.Separator;
    InputStream inputStream = assetManager.open(extPath + "file.doc");
    String text = loadFile(inputStream);
    TextView tv = (TextView) findViewById(R.id.txtv);
    tv.setText(text);
}

public String loadFile(InputStream inputStream) {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    byte[] bytes = new byte[4096];
    int length = 0;
    while () {
        b.write(bytes, 0, length);
    }
    return new String(b.toByteArray(), "UTF8");
}
相关问题