开发者

access resources of an apk

开发者 https://www.devze.com 2022-12-27 06:45 出处:网络
I\'m thinking about putting a .txt file in res/drawable or in res/layout to have it in t开发者_如何学JAVAhe apk when the application is packed, and then after install to open and read from it to perfo

I'm thinking about putting a .txt file in res/drawable or in res/layout to have it in t开发者_如何学JAVAhe apk when the application is packed, and then after install to open and read from it to perform some tasks. Can this be done? If yes please let me know how can I access the file, as I don't know it's path.


A .txt file is neither a drawable nor a layout. You should put it in res/raw. You can get access to it like:

    Resources resources = this.getResources(); 
    InputStream is = resources.openRawResource(R.raw.yourtextfile);

Try/catch and errorhandling omited in above code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号