Posted on



Import a CSV file into an Android Application from the raw resource folder and store the contents in custom data objects for use in Java.

Steps:
1. Have data in a spread sheet. Clean out ‘,’s from the data, then save as CSV file.

2. In Android project, create new resource directory
– type raw: gives name “raw”
– copy in file w/ copy/paste

3. Write code to read it.
– access the file via getResources().openRawResource(R.raw.vehicles_simple);
– use a BufferedReader to read one line at a time.
– call String.split() on the full line to create string tokens.
– parse the strings as needed and store in custom data objects.
– handle incorrectly formatted or missing data.

Nguồn:https://hdwallpaperslovely.com/

37 Replies to “Read CSV Resource File: Android Programming”

  1. can someone help me please ? what if I want to download the CSV from say Google Drive, is there a way to read the CSVfile after it has been downloaded to internal memory? Thank you

  2. Hello Brian, yours videos are very good! I would like to know how can i show into one list view the csv file. Thanks

  3. is there any way that I can output a csv file from android studio from an arraylist? I stock in this question…

  4. "No, well actually it's more interesting than I thought. It crashed. Which is FANTASTIC now we can see why."
    DrBFraser

    I appreciate the fact though that you purposefully produce terrible code so we are all reminded of how NOT to do it!

  5. Hey from Germany, very good tutorial! Iam not able to see any files in data/data…it gives me:"run-as:Could not set capabilities: Operation not permitted". iam running Ubuntu 18.04 and my real device ist a Samsung. Ive searched trough the ethernet but wasnt able to found a solution. Any Ideas? Thanks, Tobias

  6. This works great. Could you also provide a tutorial for writing data to a CSV file considering a fix to FileNotFoundException?

  7. I am struggling to get the ArrayList to display in a ListView. The adapter keeps coming up with an error, could you show how to display it in a list? I am very new to all this.

  8. Can you elaborate on how to display the results, let`s say as text displayed within the app or a chart? Very much appreciated, thank you.

  9. Thank you for your tutorial…

    But can you help how to save the result data to file .csv in Android Studio ?
    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *