Reading a txt file and outputing as a TextView in Android

后端 未结 4 1642
心在旅途
心在旅途 2021-01-07 09:46

I am trying to read a text file that is already saved in my directory and print it on the screen as a TextView. This is the code that I have so far. However, when I run the

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 10:18

    You should store those files in assets or raw directory.

    And after that you can get inputstream from those files by using ,

    If using assets

    AssetManager am = context.getAssets();
    InputStream is = am.open("test.txt");
    

    OR if you use raw directory then ,

    InputStream is = getResources().openRawResource(R.raw.test);
    

提交回复
热议问题