android studio ,play asset delivery, access asset file error

Viewed 83

I met error when I used play asset delivery in my app. My project like this: enter image description here

I want to access "hello.txt" in my default apk ,but failed! I run application like this:

I know "apk from bundle", but Android studio takes much time to compile! My question is how to access "hello.txt" when I run default apk .

enter image description here

1 Answers

you can use raw file which is a resource file:

place your .txt file in raw folder in src->main->res->raw and then in your code

InputStream inputStream = getResources().openRawResource(R.raw.yourtextfile);
BufferedReader bufferedReader= new BufferedReader(new InputStreamReader(inputStream));
String eachline = bufferedReader.readLine();

when you use assets, you are dealing with your txt just how you deal with a file, but in raw, you are dealing with a resource which is known at compile-time and more safe, it also minify during build time

Related