0

I am trying to display the contents of .doc/.docx file in the textview in Android Activity by using the code.

File sdcard = Environment.getExternalStorageDirectory();

    File file = new File(sdcard,"demo.docx");

    StringBuilder text = new StringBuilder();

    try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;

        while ((line = br.readLine()) != null) {
            text.append(line);
            text.append('\n');
        }
        br.close();
    }
    catch (IOException e) {
    }
    output.setText(text);

But, I am getting output like this,

https://i.stack.imgur.com/TAqCW.jpg

It works fine for .txt file but not for .doc/.docx file. Please Help me, how to display the contents of .doc/.docx file in textview in android activity?

Arun Sugumar
  • 9
  • 1
  • 2
  • 1
    step 1: find a library that is capable of parsing .doc and .docx files. They are *not* simple text files. – user253751 Feb 28 '15 at 05:42
  • http://stackoverflow.com/questions/15697784/displaying-a-ms-word-file-in-viewsay-textview-in-android – Daniel Nugent Feb 28 '15 at 05:55
  • Thanks for your Response, I am newbie to android so please intimate me when you find the library, whether that library works on offline. – Arun Sugumar Feb 28 '15 at 05:55
  • Thanks for your Response Daniel Nugent, If you click the link of OliveDocLibrary mentioned in that site, that will shows a 404 error. :-( Already I checked :-( – Arun Sugumar Feb 28 '15 at 06:03

1 Answers1

0

Open Microsoft Word docx file with Java

Check out that question for a general solution for parsing text.

I had the same problem but I wanted to pass the text into a java textArea not an android textView. For and Android specific solutio check out

https://github.com/plutext/AndroidDocxToHtml

Community
  • 1
  • 1
Michael Chav
  • 441
  • 5
  • 15