I am trying to read a simple text file in my sample Android Application. I am using the below written code for reading the simple text file.
1. InputStream inputStream = openFileInput("test.txt");
2. InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
3. BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
Place your text file in the
/assets directory under the Android project. Use
AssetManager class to access it.
AssetManager am = context.getAssets(); InputStream is = am.open("test.txt");
Or you can also put the file in the
/res/raw directory, where the file will be indexed and is accessible by an id in the R file:
InputStream is = context.getResources().openRawResource(R.raw.test);