Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Is it more efficient to use a text file or an XML file to store static data

I have some reference data in a text file (~5MB) that I want to use with might android application.

The file is of the format:

1|a|This is line 1a
1|b|This is line 1b
2|a|This is line 2a
2|b|This is line 2b
2|c|This is line 2c

What I want to know is the most efficient way (less memory, fast, size etc.) to use this file within my application.

a.) Should I save the file as a raw resource and open and read the whole file whenever I need a certain line.

b.) Should I convert the file to XML and use XPath to query the file when ever I need to look up a value

<!--sample XML -->
<data>
  <line number="1">
     <entry name="a">This is line 1 a</entry>
  </line>
</data>

c.) Should I just copy & paste the whole file as a static string array in the application and use that.

... any other suggestions are welcome.

[EDIT] I will also need to search this file and jump to arbitrary keywords e.g. "line 1a".

like image 825
Tawani Avatar asked Mar 01 '23 11:03

Tawani


1 Answers

XML will always take longer to read than simple text or CSV files. What XML gives you in the tradeoff is a highly structured and reliable way of storing and retrieving data. XML files are, as you can see in the examples above, a good 2-3x larger than the data they actually contain.

If you're sure that you're never going to run into the "delimiter" character in your simple text file, then that would probably work just fine, purely from a file speed perspective.

like image 50
Brandon Avatar answered Apr 07 '23 14:04

Brandon