How to read .doc file?

后端 未结 1 1443
谎友^
谎友^ 2021-01-24 14:30

I have a .doc file saved on my sdcard. I need to read the content of .doc file and show it in a TextView.

Can any

相关标签:
1条回答
  • 2021-01-24 15:23

    Sorry my mistake. You need to do this.

    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");
    }
    
    0 讨论(0)
提交回复
热议问题