Title: android parse special format txt file
Tags: android;algorithm;parsing;readfile;country
Question: I need a help to parse a special format file in Android.

The File content is pasted as follow.

????en
AL|Albania
DZ|Algeria
AD|Andorra
AO|Angola
AO_Bengo|Bengo
AO_Benguela|Benguela
AO_Bie|Bie
AO_Cabinda|Cabinda
AO_Cuando Cubango|Cuando Cubango
AO_Cuanza Norte|Cuanza Norte
AO_Cuanza Sul|Cuanza Sul
AO_Cunene|Cunene
AO_Huambo|Huambo
AO_Huila|Huila
AO_Luanda|Luanda
????en

The file content startwith character "????" I need parse country code and city code in a high way.


Here is the accepted answer: Document is pretty chaotic... maybe you may use not parser, but something like this:

```    ArrayList<String&gt; countries = new ArrayList<String&gt;();
    ArrayList<String&gt; sities = new ArrayList<String&gt;();
    ArrayList<String&gt; codes= new ArrayList<String&gt;();
        try {
            BufferedReader br = new BufferedReader(new FileReader(filepath));
            String line = "";
            while ((line = br.readLine()) != null) {
                if(!line.contains("?")){
                String[] data = line.split(("\\|"); // this part maybe you should modify by yourself
                    codes.add(data[0]);
                    countries.add(data[0]);
                    cities.add(data[0]);
                }
            }
            br.close();
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
```

Hope it will be useful.

Comment for this answer: may be my question is not clear. But your answer is helpful for my question. Thx.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:01/14/15', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<android><algorithm><parsing><readfile><country>', 'Title': 'android parse special format txt file', 'ViewCount': 64, 'id': 27937200, 'user_AboutMe': None, 'user_AccountId': 5622943.0, 'user_DisplayName': 'bignewyork', 'user_Reputation': 23.0, 'user_Views': 4.0, 'user_id': 4452160.0}}