DRing
DRing

Reputation: 7039

How to parse custom file in Android

I am making a reader for a program that I use. The info is exported in a custom filetype (.BSMX). When I open the file up in notepad it is a bunch of tags similar in structure to XML. Im wondering how I can parse the file like you would a XML file in order to store the data into a custom object to use the data.

Edit: heres a section of the file and how its formatted, its not XML and doesnt have the xml code at the top

            <_MOD_>2012-03-23</_MOD_>
            <F_E_NAME>FUggin Hiccups BIAB</F_E_NAME>
            <F_E_MASH_VOL>896.0000000</F_E_MASH_VOL>
            <F_E_TUN_MASS>35.2000000</F_E_TUN_MASS>
            <F_E_BOIL_RATE_FLAG>1</F_E_BOIL_RATE_FLAG>
            <F_E_TUN_SPECIFIC_HEAT>0.1200000</F_E_TUN_SPECIFIC_HEAT>
            <F_E_TUN_DEADSPACE>0.0000000</F_E_TUN_DEADSPACE>
            <F_E_TUN_ADJ_DEADSPACE>0</F_E_TUN_ADJ_DEADSPACE>
            <F_E_CALC_BOIL>1</F_E_CALC_BOIL>
            <F_E_BOIL_VOL>894.7200000</F_E_BOIL_VOL>
            <F_E_BOIL_TIME>60.0000000</F_E_BOIL_TIME>
            <F_E_OLD_EVAP_RATE>10.0000000</F_E_OLD_EVAP_RATE>
            <F_EQUIP_39>1</F_EQUIP_39>
            <F_E_BOIL_OFF>96.0000000</F_E_BOIL_OFF>
            <F_E_TRUB_LOSS>128.0000000</F_E_TRUB_LOSS>
            <F_E_COOL_PCT>4.0000000</F_E_COOL_PCT>
            <F_E_TOP_UP_KETTLE>256.0000000</F_E_TOP_UP_KETTLE>
            <F_E_BATCH_VOL>640.0000000</F_E_BATCH_VOL>
            <F_E_FERMENTER_LOSS>64.0000000</F_E_FERMENTER_LOSS>
            <F_E_TOP_UP>0.0000000</F_E_TOP_UP>
            <F_E_EFFICIENCY>67.4000000</F_E_EFFICIENCY>
            <F_E_HOP_UTIL>100.0000000</F_E_HOP_UTIL>
        </F_R_EQUIPMENT>

Upvotes: 0

Views: 142

Answers (2)

user717572
user717572

Reputation: 3652

Since your file contents resemble XML, you could best try SAXParser. You can make a custom ContentHandler with this, so you basically specify your tags, and you can code yourself how the file will be parsed.

Otherwise if SAXParser doesn't work (no xml file), you must parse it by hand, or better, make the file structured like an xml file.

Upvotes: 1

TSGames
TSGames

Reputation: 679

It would be helpful if you post an example how the file looks like.

Basically, depending on the size of the file, you could use an InputStream reader, read the file entirley into a String and split this string by tags using something like the .split() method. After that, you can store the data you need into an array.

Upvotes: 0

Related Questions