From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Read files from assets

Read files from assets

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Read files from assets

- [Instructor] You can package data files in either the resources directory or in a special folder named assets. There isn't any performance advantage of one over the other, but each strategy has its benefits. Resource files give you a generated resource identifier to refer to in your code. If you misspell the identifier, you'll get a compiler error. And, storing files as resources also lets you localize your application easily. You can have one version of the data, say, for English, and others for French, German, or any other languages you want to support. In contrast, assets will be referred to by their names as strings, so it gives you some flexibility. You can build filenames dynamically at runtime. I'm going to copy my resource file, monster_data.json, into a new assets directory. I'll go to my app module and right click and choose New -> Folder -> Assets Folder. The default location for the assets folder is under the main directory in the project, and that's where I'll keep it…

Contents