Brian Fraser | Read CSV Resource File: Android Programming @DrBFraser | Uploaded 7 years ago | Updated March 01 2023
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.
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.