-3

I am trying to search for a way to open a text file in an Activity from the assets folder in android.

I have done some RnD on the topic but couldn't find an answer that precisely matches my needs.
opening the text file is very much needed for my project.

Any help will be appreciated.

Mayur Birari
  • 5,837
  • 8
  • 34
  • 61
Akshay
  • 1
  • 2
  • what do you want to do with that file. Depending on what you want to do, there are several ways to open a file. – Raigex Jul 15 '13 at 18:38
  • You might want to look at http://stackoverflow.com/questions/9544737/read-file-from-assets. HpTerm has a great example of this. – tbritson Jul 15 '13 at 18:56
  • `i done a thorough RnD on the topic` - Really? I Googled for `android open text file assets` and got many answers in 10 seconds. – Simon Jul 15 '13 at 18:57

1 Answers1

2
InputStream is = this.getAssets().open("file.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;

while ((line = reader.readLine()) != null) {
    // use line variable
}

reader.close();
Voicu
  • 16,921
  • 10
  • 60
  • 69