---
title: "How to Reading and parsing text file android?"  
description: "How to Reading and parsing text file android?"  
author: "Jayden Bell"  
published: 2014-10-14  
updated: 2014-10-14  
canonical: https://www.mindstick.com/forum/2376/how-to-reading-and-parsing-text-file-android  
category: "android"  
tags: ["android", "mobile development"]  
reading_time: 4 minutes  

---

# How to Reading and parsing text file android?

Recently, I've come accross an [interesting challenge](https://answers.mindstick.com/qa/94403/what-was-the-most-interesting-challenge-you-faced-while-developing-an-android-application), which I apparently cannot solve. I'am an [android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios) [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas), and what interests me is: How does one read from a [text file](https://www.mindstick.com/forum/12828/converting-a-text-file-to-an-array-in-java)(on phone, as a user) and [store](https://www.mindstick.com/articles/13125/tips-to-increase-sales-of-your-woocommerce-store) that parsed file into a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp), processes the string, the outputs it?

## for example:

code to read a file . . code to count [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) . . . code to print the [result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) on the [phone screen](https://answers.mindstick.com/qa/109586/how-to-restoration-android-phone-screen-rotation-troubles).

## Replies

### Reply by Anonymous User

Background Async Task to load and parse filename.csv

```
class LoadAllIcosSD extends AsyncTask<String, String, String> {    /**     * Before starting background thread Show Progress Dialog     * */    @Override    protected void onPreExecute() {        super.onPreExecute();        pDialog = new ProgressDialog(SynchroIcoActivitySD.this);        pDialog.setMessage(getString(R.string.progdata));        pDialog.setIndeterminate(false);        pDialog.setCancelable(false);        pDialog.show();    }    protected String doInBackground(String... args) {        try {            String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();            String fileName = "/myfolder/filename.csv";            File myFile = new File(baseDir + File.separator + fileName);            if(myFile.exists()){            FileInputStream fIn = new FileInputStream(myFile);            BufferedReader myReader = new BufferedReader(                    new InputStreamReader(fIn));            String aDataRow = "";            String aBuffer = "";            //how many row            int ip=0;            while ((aDataRow = myReader.readLine()) != null) {                aBuffer += aDataRow + "\n";                ip = ip+1;            }            String kosikx = aBuffer;            myReader.close();            String delims = "[\n]+";            String delims2 = "[;]+";            String[] riadokxxx = kosikx.split(delims);            for (int i = 0; i < riadokxxx.length; i++) {            String riadok1 =  riadokxxx[i];            String[] polozkyx = riadok1.split(delims2);            String icox =  polozkyx[0];            String naix =  polozkyx[3] + " " + polozkyx[6];            // creating new HashMap            HashMap<String, String> map = new HashMap<String, String>();            // adding each child node to HashMap key => value            map.put(TAG_PID, icox);            map.put(TAG_NAME, naix);            map.put(TAG_PRICE, "!!");            // adding HashList to ArrayList            productsList.add(map);                 }            }//iffileexist        } catch (Exception e) {        }        return null;    }    /**     * After completing background task Dismiss the progress dialog     * **/    protected void onPostExecute(String file_url) {        // dismiss the dialog after getting all products        pDialog.dismiss();        // updating UI from Background Thread        runOnUiThread(new Runnable() {            public void run() {                /**                 * Updating parsed JSON data into ListView                 * */                ListAdapter adapter = new SimpleAdapter(                        SynchroIcoActivitySD.this, productsList,                        R.layout.list_item_icosd, new String[] { TAG_PID, TAG_NAME, TAG_PRICE},                        new int[] { R.id.pid, R.id.name, R.id.price });                // updating listview                setListAdapter(adapter);            }        });    }}
```


---

Original Source: https://www.mindstick.com/forum/2376/how-to-reading-and-parsing-text-file-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
