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


10 responses to “Reading / Parsing CSV File

  1. 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.

  2. 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?


  3. 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

  4. 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.

  5. 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: