rantravee
rantravee

Reputation: 7421

access resources of an apk

I'm thinking about putting a .txt file in res/drawable or in res/layout to have it in the 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.

Upvotes: 1

Views: 713

Answers (1)

Maurits Rijk
Maurits Rijk

Reputation: 9985

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.

Upvotes: 5

Related Questions