Load a simple text file in Android Studio

后端 未结 3 839
-上瘾入骨i
-上瘾入骨i 2020-12-05 00:16

Got a brand new project using Google\'s new Android Studio IDE.

I\'m trying to load a simple text file using an InputStreamReader. I\'m getting a file n

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 01:03

    The correct answer didn't work for me exactly. This works:

    Go to Project view and then go to app/src/main and create new directory assets

    to load the file:

       InputStream is = getApplicationContext().getAssets().open("bla.txt");
    

    or:

       InputStream is = context.getAssets().open("bla.txt");
    

    and then convert it to string at any way you want, examples here

    detailed video of how to do it (not mine)

提交回复
热议问题