I’m making an dictionary app for android. This app uses stardict and DICT files which is are often pretty large (10MB or more) and contains just plain texts.
When users look up a word, my app will read the file randomly and return the result. I’ve read on some articles that reading file is expensive and slow. So I wonder if bringing all data into database is a better solution?
I would suggest putting your words into a database for the following reasons:
- DB lookups on android with SQLite are “fast enough” (~1ms) for even the most impatient of users
- Reading large files into memory is a dangerous practice in memory-limited environments such as android.
- Trying to read entries out of a file “in place” rather than “in memory” is effectively trying to solve all the problems that SQLite already solves for you.
The only challenge presented in using a database is initializing it with the data you require. This problem can best be solved by creating the desired database in advance and then attaching it to your APK assets. There is an example here that is quite good.
Hope this helps.