read file from assets

前端 未结 18 2251
终归单人心
终归单人心 2020-11-21 22:47
public class Utils {
    public static List getMessages() {
        //File file = new File(\"file:///android_asset/helloworld.txt\");
        AssetMan         


        
18条回答
  •  -上瘾入骨i
    2020-11-21 23:48

    getAssets()
    

    is only works in Activity in other any class you have to use Context for it.

    Make a constructor for Utils class pass reference of activity (ugly way) or context of application as a parameter to it. Using that use getAsset() in your Utils class.

提交回复
热议问题