-3

I am creating an application where data are saved in .txt file in assets folder, I am trying to retrieve my data but I am not able to do, My teacher conditions to not to use SQLite and shared preference.

Shivputra N
  • 688
  • 7
  • 17
Giang Hoàng
  • 11
  • 1
  • 2
  • you can copy the string to string.xml and create a string-array in string.xml. Fetch the story list from the array and display in listview. For showing the story fetch each story from string.xml – Rahul Baradia Dec 30 '15 at 09:33
  • I have use create string in value but i want to save in assert. Have another way ? – Giang Hoàng Dec 30 '15 at 09:42

1 Answers1

0

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 = getResources().openRawResource(R.raw.test);
Shivputra N
  • 688
  • 7
  • 17