Reading / Parsing CSV File

20 Feb

App Inventor includes a Storage File component that can be used for reading and writing. One use of this component can be for reading CSV (Comma Separated File) as key value pairs.

Assume you have a a file called myDataFile.csv with contents that includes authors (key) and books (values) like below. Note that in below example, the value can be varible-size tokenized string (string with multiple values):

Hossein,Absolute App Inventor 2|Amazon|Google Play Book|Apple Book Store
Dave Wolber,App Inventor|Google

The code below shows how we can use a TEXT field to get a user-entered key and then search the data-file and return the search data into another TEXT filed. The code below will loop through the tokenized string value and print each token.



Posted by on February 20, 2015 in Uncategorized


16 responses to “Reading / Parsing CSV File

  1. Hosam Mohamed

    February 9, 2018 at 1:32 pm

    thank you, but this error ( is not a well-formed list of pairsNote:&nbsp )

    this means my csv file is wrong

    • Hossein Amerkashi

      February 9, 2018 at 2:44 pm

      You should post more details to

    • Hosam Mohamed

      February 10, 2018 at 1:24 pm

      Thank you for the quick reply ..
      The file contains 3 rows (the name – code – number) that is required to enter the code and it will search and show the name and number of this code, but after execution, you will receive an error message (look in pairs: the list ( ; 2) (b; 4) (c; 6) (d; 8) (e; 10)) is not a well-formed list of pairs Note: a well-formed list of pairs Note: & nbsp;

  2. Ron

    June 10, 2017 at 6:55 pm

    I have an app that loads a csv into tinydb on screen1 initialize. I then move to screen2, then back to screen1, and the app crashes with a memory error.
    Is it best to somehow only load the csv *once*? Could my screen1 be causing the memory problem by overloading tinydb unnecessarily?

    • Lou Meylemans

      June 11, 2017 at 8:14 am

      Hi Ron,
      have you already tried to keep it all in 1 screen, making the 2 layouts in different arrangements which you can make visible or not?

  3. Ashutosh

    August 20, 2015 at 8:35 am

    Hi, I am new to this. I was trying to execute the code and my doubt is that where to put myDataFile.csv when using Emulator.

    • Hossein Amerkashi

      August 20, 2015 at 9:40 am

      When in Designer, just upload the .csv file as Media. It will be saved into assets folder

      • Kurt Pidgeon

        February 11, 2016 at 7:49 am

        Hi! Thanks for the post, when I connect to a device, the app runs well. When I build the app, it doesn’t work. It’s like it can’t find the data.
        Any ideas?

        • Hossein Amerkashi

          February 11, 2016 at 8:11 am

          Hi, For production, try using file:///android_asset/myCsv.txt

          • Kurt Pidgeon

            February 11, 2016 at 2:28 pm

            Hi. It turns out that just //Csv.txt works. My mistake is that just connecting to the device isn’t case sensitive however, packaging the app is case sensitive. Thanks for your help Hossein, I’ll do my best to pass it on.

  4. Iris

    June 25, 2015 at 4:08 am

    Hi – I encountered your blog online, looking for the answer to a question; perhaps you can help me?

    I’m studying a course in App Inventor (expires in about a week; time is of the essence!), and I am stuck, because the video tutorial is using App Inventor Classic, and I am using AI2.

    I am stuck trying to learn how to create an email form, in a Business Card App.

    Do you know how, or have access to a tutorial that teaches how to create an email form in an app, using AI2?


  5. sankari

    June 10, 2015 at 12:00 pm

    thanks for your post.
    My csv file looks like this —
    and so on

    I have a listview in which countries are listed.
    Listview items —- Greece,UK,USA,China,Japan

    When an item is selected, its selected index is matched with that of csv file (1st field) and the corresponding row should be displayed.

    For example, if UK is selected, its selected index is 2. Therefore 2nd row from csv file (2, London) should be displayed in a text box.

    I am able to get the first row only for rest of the rows. I get this error ; The operation select list item cannot accept the arguments (2, London;5) – when I click 5th item, Japan

    Pl help me

  6. AppInventor-Sam

    March 12, 2015 at 6:12 am

    Thank you Hossein that was a helpful post. Do you have a tutorial or can you have a tutorial on App Inventor’s chart. I have been looking for a reference/example as to how to read a text file and draw a stock chart with zoom.

    Your input will be greatly appreciated.

  7. habboubih

    February 22, 2015 at 3:52 pm

    The block image is too small and unreadable.

    • Hossein Amerkashi

      February 23, 2015 at 11:00 am

      Use control + to zoom in. Let us know if that helps


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: