How to access a file from asset/raw directory

后端 未结 5 1143
南笙
南笙 2020-11-30 12:34

with this below code i\'m trying to access the file which is stored in asset/raw folder, but getting null and

E/ERR: file:/android         


        
5条回答
  •  旧时难觅i
    2020-11-30 12:53

    Place your text file in the /assets directory under the Android project and use AssetManager class as follows to access it.

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

    Or you can also put the file in the /res/raw directory, from where the file can be accessed by an id as follows

    InputStream is = 
    context.getResources().openRawResource(R.raw.default_book);
    

提交回复
热议问题