FileReader for text file in Android

Eugene Shmorgun picture Eugene Shmorgun · Sep 24, 2011 · Viewed 27k times · Source

Good times!

My Android app is trying to read simple text file, using usual Java combination

FileReader fr = new FileReader("file:///android_asset/example.txt");
BufferedReader bfr = new BufferedReader(fr);

But what ever I do, I'm getting File not Found exeption, although there is another html-file in this directory and shown in WebView correctly.
So, my question is:
FileReader can be used for simple reading text file or I have to use InputStream ?

Answer

Android Killer picture Android Killer · Sep 24, 2011

You have to InputStream like as follows.Change the code like this.I hope it will work:

FileInputStream fis = new FileInputStream("file:///android_asset/example.txt");
BufferedReader bfr = new BufferedReader(new InputStreamReader(fis));