Try OpenCSV - it will make your life easier.

First, add this package to your gradle dependencies as follows

implementation 'com.opencsv:opencsv:4.6'

Then you can either do

import com.opencsv.CSVReader;
import java.io.IOException;
import java.io.FileReader;


...

try {
    CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
    String[] nextLine;
    while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        System.out.println(nextLine[0] + nextLine[1] + "etc...");
    }
} catch (IOException e) {

}

or

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
List myEntries = reader.readAll();

Edit after comment

try {
    File csvfile = new File(Environment.getExternalStorageDirectory() + "/csvfile.csv");
    CSVReader reader = new CSVReader(new FileReader(csvfile.getAbsolutePath()));
    String[] nextLine;
    while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        System.out.println(nextLine[0] + nextLine[1] + "etc...");
    }
} catch (Exception e) {
    e.printStackTrace();
    Toast.makeText(this, "The specified file was not found", Toast.LENGTH_SHORT).show();
}

If you want to package the .csv file with the application and have it install on the internal storage when the app installs, create an assets folder in your project src/main folder (e.g., c:\myapp\app\src\main\assets\), and put the .csv file in there, then reference it like this in your activity:

String csvfileString = this.getApplicationInfo().dataDir + File.separatorChar + "csvfile.csv"
File csvfile = new File(csvfileString);
Answer from buradd on Stack Overflow
Top answer
1 of 7
49

Try OpenCSV - it will make your life easier.

First, add this package to your gradle dependencies as follows

implementation 'com.opencsv:opencsv:4.6'

Then you can either do

import com.opencsv.CSVReader;
import java.io.IOException;
import java.io.FileReader;


...

try {
    CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
    String[] nextLine;
    while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        System.out.println(nextLine[0] + nextLine[1] + "etc...");
    }
} catch (IOException e) {

}

or

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
List myEntries = reader.readAll();

Edit after comment

try {
    File csvfile = new File(Environment.getExternalStorageDirectory() + "/csvfile.csv");
    CSVReader reader = new CSVReader(new FileReader(csvfile.getAbsolutePath()));
    String[] nextLine;
    while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        System.out.println(nextLine[0] + nextLine[1] + "etc...");
    }
} catch (Exception e) {
    e.printStackTrace();
    Toast.makeText(this, "The specified file was not found", Toast.LENGTH_SHORT).show();
}

If you want to package the .csv file with the application and have it install on the internal storage when the app installs, create an assets folder in your project src/main folder (e.g., c:\myapp\app\src\main\assets\), and put the .csv file in there, then reference it like this in your activity:

String csvfileString = this.getApplicationInfo().dataDir + File.separatorChar + "csvfile.csv"
File csvfile = new File(csvfileString);
2 of 7
11

The following snippet reads a CSV file from the raw resources folder (which will be packed into your .apk file upon compilation).

Android by default does not create the raw folder. Create a raw folder under res/raw in your project and copy your CSV File into it. Keep the name of the CSV file lower case and convert it into text format when asked. My CSV file name is welldata.csv.

In the snippet, WellData is the model class (with constructor, getter and setter) and wellDataList is the ArrayList to store the data.

private void readData() {
    InputStream is = getResources().openRawResource(R.raw.welldata);
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(is, Charset.forName("UTF-8")));
    String line = "";

    try {
        while ((line = reader.readLine()) != null) {
           // Split the line into different tokens (using the comma as a separator).
            String[] tokens = line.split(",");

            // Read the data and store it in the WellData POJO.
            WellData wellData = new WellData();
            wellData.setOwner(tokens[0]);
            wellData.setApi(tokens[1]);
            wellData.setLongitude(tokens[2]);
            wellData.setLatitude(tokens[3]);
            wellData.setProperty(tokens[4]);
            wellData.setWellName(tokens[5]);
            wellDataList.add(wellData);

            Log.d("MainActivity" ,"Just Created " + wellData);
        }
    } catch (IOException e1) {
        Log.e("MainActivity", "Error" + line, e1);
        e1.printStackTrace();
    }
}
๐ŸŒ
Javapapers
javapapers.com โ€บ android โ€บ android-read-csv-file
Android Read CSV File - Javapapers
So how to load the CSV file from โ€œrawโ€ folder and use the above utility to read it? ... CSVFile is the above utility Java class (no external API used). InputStream inputStream = getResources().openRawResource(R.raw.stats); CSVFile csvFile = new CSVFile(inputStream); List ... Now lets look at this example Android application where we have used a CSV file to load data.
Discussions

applications - How to open .csv file on Android? - Android Enthusiasts Stack Exchange
CSV File Viewer For Android | CSV Reader - view small and large-sized CSV files. More on android.stackexchange.com
๐ŸŒ android.stackexchange.com
How to read csv file in android? - Stack Overflow
Possible Duplicate: Get and Parse CSV file in android I would like to store a csv file in android app itself & it should be called for read & later print the values according to the More on stackoverflow.com
๐ŸŒ stackoverflow.com
How can I read and show data from a csv file in Android? - Stack Overflow
I'm trying to understand how I can read from a csv file and show it on an activity in android studio. The file can contain for instance these information: name,employer,location,position type,core More on stackoverflow.com
๐ŸŒ stackoverflow.com
Import csv data on android (or the web)
u/derFalscheMichel - Your post was submitted successfully. Once your problem is solved, reply to the answer(s) saying Solution Verified to close the thread. Follow the submission rules -- particularly 1 and 2. To fix the body, click edit. To fix your title, delete and re-post. Include your Excel version and all other relevant information Failing to follow these steps may result in your post being removed without warning. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
๐ŸŒ r/excel
4
2
July 4, 2024
๐ŸŒ
en.proft.me
en.proft.me โ€บ 2017 โ€บ 07 โ€บ 6 โ€บ how-read-csv-file-android
How to read from CSV file in Android | en.proft.me
public class MainActivity extends AppCompatActivity { RatingBar ratingBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); List<String[]> rows = new ArrayList<>(); CSVReader csvReader = new CSVReader(RatingActivity.this, "movies.csv"); try { rows = csvReader.readCSV(); } catch (IOException e) { e.printStackTrace(); } for (int i = 0; i < rows.size(); i++) { Log.d(Constants.TAG, String.format("row %s: %s, %s", i, rows.get(i)[0], rows.get(i)[1])); } } }
๐ŸŒ
Aknay
aknay.github.io โ€บ 2018 โ€บ 09 โ€บ 28 โ€บ how-to-open-a-csv-file-from-android.html
How to open a CSV file from Android App
In this tutorial, we will open a CSV file using Android storage access framework. Then read the content of the CSV file and load the data to display on the App.
๐ŸŒ
Google Play
play.google.com โ€บ store โ€บ apps โ€บ details
CSV File Viewer - Apps on Google Play
May 15, 2026 - CSV File Viewer imports and reads .CSV files effortlessly and directly from your android device. If you work with data sets, or you need to view spreadsheet data, this is the perfect tool for you. Whether you are a data analyst, business professional, or simply someone who frequently works with CSV files, our CSV Viewer App ...
Rating: 3.7 โ€‹ - โ€‹ 9.56K votes
๐ŸŒ
YouTube
youtube.com โ€บ brian fraser
Read CSV Resource File: Android Programming - YouTube
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...
Published ย  February 26, 2017
Views ย  64K
Find elsewhere
๐ŸŒ
The App Guruz
theappguruz.com โ€บ blog โ€บ parse-csv-file-in-android-example-sample-code
How to Parse CSV file in Android with sample
... String next[] = {}; List<string[]> list = new ArrayList<string[]>(); try { CSVReader reader = new CSVReader(new InputStreamReader(getAssets().open("test.csv")));//Specify asset file name //in open(); for(;;) { next = reader.readNext(); if(next != null) { list.add(next); } else { break; ...
๐ŸŒ
Example Code
example-code.com โ€บ android โ€บ csv_read.asp
Androidโ„ข Read CSV File
Chilkat ย• HOME ย• Androidโ„ข ย• AutoIt ย• C ย• C# ย• C++ ย• Chilkat2-Python ย• CkPython ย• Classic ASP ย• DataFlex ย• Delphi DLL ย• Go ย• Java ย• Node.js ย• Objective-C ย• PHP Extension ย• Perl ย• PowerBuilder ย• PowerShell ย• PureBasic ย• Ruby ย• SQL Server ย• Swift ย• Tcl ย• Unicode C ย• ...
๐ŸŒ
dotTech
dottech.org โ€บ home โ€บ android โ€บ how to open and read csv files in android [tip]
How to open and read CSV files in Android [Tip] | dotTechdotTech
March 6, 2015 - Open the Play Store app from your Android device. Search for the โ€œCSV Viewerโ€ app and then install it on your tablet or phone. Alternatively, you can just click here to go to the appโ€™s official Play Store page.
๐ŸŒ
GitHub
github.com โ€บ Ibrahim-Mushtaha โ€บ Read-CSV-Resource-File-App
GitHub - Ibrahim-Mushtaha/Read-CSV-Resource-File-App: Simple android app to read CSV files.
Simple android app to read CSV files. Contribute to Ibrahim-Mushtaha/Read-CSV-Resource-File-App development by creating an account on GitHub.
Author ย  Ibrahim-Mushtaha
๐ŸŒ
Gadgets To Use
gadgetstouse.com โ€บ home โ€บ 3 ways to open and edit csv files on android phone
3 Ways to Open and Edit CSV Files on Android Phone - Gadgets To Use
October 4, 2022 - CSV Viewer App is a complete Android app to deal with all the CSV files. Using this app, you can even write and read data codes of table designing. It also offers rich features such as data analysis and charts to run calculations.
Top answer
1 of 2
3

You are indeed confused and mixing some things up. Let's go step by step.

STEP BY STEP, QUESTION BY QUESTION

  1. A class and an activity are not the same. You can read about it here and here. To put it in an easy way:

    • A class is a Java form.
    • For each screen in your app you will have a different activity. Each of them might have more than one class.
  2. Then, in Android, if you want to do any app (including the one which needs to read the .csv) you will need an activity, so that there is at least one screen in which the user can be. That is to say that the first thing you will need to do is to create an activity and add it to the manifest as the default activity (so that it appears together with the rest of apps). Do this (create activity), and then this (set it as default).

  3. Now you should be able to try the app in an emulator or a physical device and see an empty screen that does nothing.

  4. So far, so good. Now to the .csv reading problem. We will read the code as soon as the user enters the activity, when the activity is created (in the onCreate method). There should be a piece of code like the following one in your activity, otherwise, create it.

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
  1. Now we will proceed to read the csv inside the onCreate (you could also do it when the user presses a button, etc.). Note that one thing is reading it and the other one is creating visible UI lists with it. Here you can see how to read a csv file (either if you have it in the sd or if you pack it with the app).

EDIT. Let's deep deeper into this step (5). As stated in the answer I have referenced, you need to:

Add this package to your gradle dependencies as follows

implementation 'com.opencsv:opencsv:4.6'

And then modify the onCreate (or wherever you want to read the csv):

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

try {
// OPTION 1: if the file is in the sd
    File csvfile = new File(Environment.getExternalStorageDirectory() + "/csvfile.csv"); 
// END OF OPTION 1

// OPTION 2: pack the file with the app
/* "If you want to package the .csv file with the application and have it install on the internal storage when the app installs, create an assets folder in your project src/main folder (e.g., c:\myapp\app\src\main\assets\), and put the .csv file in there, then reference it like this in your activity:" (from the cited answer) */
String csvfileString = this.getApplicationInfo().dataDir + File.separatorChar + "csvfile.csv"
File csvfile = new File(csvfileString);
// END OF OPTION 2

    CSVReader reader = new CSVReader(new FileReader("csvfile.getAbsolutePath()"));
    String[] nextLine;
    while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        System.out.println(nextLine[0] + nextLine[1] + "etc...");
    }
} catch (Exception e) {
    e.printStackTrace();
    Toast.makeText(this, "The specified file was not found", Toast.LENGTH_SHORT).show();
}
}

FINALLY

Right, so this would be it. If you also wanted to represent this data in a list, a grid, etc., well, this is another question! However, just in case, you just need to use again the activity you created, but add the ListView to your layout and feed the list also in onCreate (for example). See a tutorial here.

2 of 2
0

You can use TableUIBuilder to read your CSV file and render it as TableLayout as follows:-

((ViewGroup) findViewById(R.id.tableContainer)).addView(new TableUIBuilder(this, "student_records.csv").build());
๐ŸŒ
Reddit
reddit.com โ€บ r/excel โ€บ import csv data on android (or the web)
r/excel on Reddit: Import csv data on android (or the web)
July 4, 2024 -

For context: I'd like to compare election results over multiple elections from the past few years in my district.

The data I got access to is quite a broad arrangement of text files with pages of data separated by varying amounts of semicolons. I tried to simply convert to .csv, but that way excel just sorts them into like a thousand columns, but doesn't add a single row.

I tried the webversion, but next to the fact that its very glitchy, the whole split into columns isn't particularly useful if I don't want to spend hours dragging data vertically.

What I like to do is arrange the data quite simply by minor district, amount of voters, amount of votes for party A and so on, and ultimately compare it with other elections in a single sheet.

Do you have any idea how I could import the data in a way that will save me all that? In theory, it seems pretty simple, but right now it seems impossible to me, despite having all the data delivered on a silver plate

๐ŸŒ
Google Play
play.google.com โ€บ store โ€บ apps โ€บ details
CSV Reader - CSV Viewer - Apps on Google Play
May 19, 2026 - CSV Reader is a versatile app designed to make opening and managing CSV files effortless on your Android device. With its intuitive interface and essential controls, you can quickly access and view your CSV files without the need for an internet ...
Rating: 4 โ€‹ - โ€‹ 1.87K votes
Top answer
1 of 5
21

Where to put the CSV file in Android Create a folder named โ€œrawโ€ inside the โ€œresโ€ folder and put the CSV file in it.

How to read CSV file, Nothing special since its Android. All we are going to use our standard Java code. Its better to use our own code instead of going to an API. Following class is an utility to read CSV file and it can be used from within the Android application. In which array we will store items of csv file In these example it is scorelist arraylist .

public class CSVFile {
    InputStream inputStream;

    public CSVFile(InputStream inputStream){
        this.inputStream = inputStream;
    }

    public List read(){
        List resultList = new ArrayList();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        try {
            String csvLine;
            while ((csvLine = reader.readLine()) != null) {
                String[] row = csvLine.split(",");
                resultList.add(row);
            }
        }
        catch (IOException ex) {
            throw new RuntimeException("Error in reading CSV file: "+ex);
        }
        finally {
            try {
                inputStream.close();
            }
            catch (IOException e) {
                throw new RuntimeException("Error while closing input stream: "+e);
            }
        }
        return resultList;
    }
}

So how to load the CSV file from โ€œrawโ€ folder and use the above utility to read it?

InputStream inputStream = getResources().openRawResource(R.raw.stats);
CSVFile csvFile = new CSVFile(inputStream);
List scoreList = csvFile.read();

MainActivity.java

public class MainActivity extends Activity {
    private ListView listView;
    private ItemArrayAdapter itemArrayAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.listView);
        itemArrayAdapter = new ItemArrayAdapter(getApplicationContext(), R.layout.item_layout);

        Parcelable state = listView.onSaveInstanceState();
        listView.setAdapter(itemArrayAdapter);
        listView.onRestoreInstanceState(state);

        InputStream inputStream = getResources().openRawResource(R.raw.stats);
        CSVFile csvFile = new CSVFile(inputStream);
        List scoreList = csvFile.read();

        for(String[] scoreData:scoreList ) {
            itemArrayAdapter.add(scoreData);
        }
    }
}

ItemArrayAdapter.java

public class ItemArrayAdapter extends ArrayAdapter {
    private List scoreList = new ArrayList();

    static class ItemViewHolder {
        TextView name;
        TextView score;
    }

    public ItemArrayAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    }

    @Override
    public void add(String[] object) {
        scoreList.add(object);
        super.add(object);
    }

    @Override
    public int getCount() {
        return this.scoreList.size();
    }

    @Override
    public String[] getItem(int index) {
        return this.scoreList.get(index);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ItemViewHolder viewHolder;
        if (row == null) {
            LayoutInflater inflater = (LayoutInflater) this.getContext().
                    getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.item_layout, parent, false);
            viewHolder = new ItemViewHolder();
            viewHolder.name = (TextView) row.findViewById(R.id.name);
            viewHolder.score = (TextView) row.findViewById(R.id.score);
            row.setTag(viewHolder);
        } else {
            viewHolder = (ItemViewHolder)row.getTag();
        }
        String[] stat = getItem(position);
        viewHolder.name.setText(stat[0]);
        viewHolder.score.setText(stat[1]);
        return row;
    }
}

activity_mail.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.javapapers.android.csvfileread.app.MainActivity">
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/listView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp" />
</RelativeLayout>

item_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/name"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/score"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="20dp" />
</RelativeLayout>

For the whole source code you can refers to these link javapapers.com/wp-content/uploads/2014/07/CSVFileRead.zip

I think it will help

2 of 5
5

A better CSV parser handles quoted fields

    import android.content.Context;
    import android.widget.Toast;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;

    public class CSVReader {
        private class StringDArray {
            private String[] data=new String[0];
            private int used=0;
            public void add(String str) {
                if (used >= data.length){
                    int new_size= used+1;
                    String[] new_data=new String[new_size];
                    java.lang.System.arraycopy( data,0,new_data,0,used);
                    data=new_data;
                }
                data[used++] = str;
            }
            public int length(){
                return  used;
            }
            public String[] get_araay(){
                return data;
            }
        }
        private  Context context;
        public CSVReader(Context context){
            this.context=context;
        }
        public List read(File file){
            List resultList = new ArrayList();
            try{
                InputStream inputStream= new FileInputStream(file);
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                String csvLine;
                final char Separator = ',';
                final char Delimiter = '"';
                final char LF = '\n';
                final char CR = '\r';
                boolean quote_open = false;
                while ((csvLine = reader.readLine()) != null) {
                    //String[] row = csvLine.split(",");// simple way
                    StringDArray a=new StringDArray();
                    String token="";
                        csvLine+=Separator;
                    for(char c:csvLine.toCharArray()){
                        switch (c){
                            case LF: case CR:// not required as we are already read line
                                quote_open=false;
                                a.add(token);
                                token="";
                            break;
                            case Delimiter:
                                quote_open=!quote_open;
                            break;
                            case Separator:
                                if(quote_open==false){
                                    a.add(token);
                                    token="";
                                }else{
                                    token+=c;
                                }
                            break;
                            default:
                                token+=c;
                            break;
                        }
                    }
                    if(a.length()>0 ) {
                        if(resultList.size()>0){
                            String[] header_row =(String[]) resultList.get(0);
                            if(a.length()>=header_row.length) {
                                String[] row = a.get_araay();
                                resultList.add(row);
                            }
                        }else{
                            String[] row = a.get_araay();
                            resultList.add(row);//header row
                        }
                    }
                }
                inputStream.close();
            }catch (Exception e){
                Toast.makeText(context,"Error : " + e.getMessage(), Toast.LENGTH_LONG).show();
            }
            return resultList;
        }
    }

Usage

    File file=new File(path);
    CSVReader csvReader=new CSVReader(activity.this);
    List csv=csvReader.read(file);
    if(csv.size()>0){
        String[] header_row =(String[]) csv.get(0);
        if(header_row.length>1){
            String col1=header_row[0];
            String col2=header_row[1];
        }
    }

    Toast.makeText(activity.this,csv.size() + " rows", Toast.LENGTH_LONG).show();

Sample data used
ID,Name
1,Test Item 1
"2","Test Item 2"
"3","Test , Item 3"
4,Test Item 4

๐ŸŒ
GitHub
github.com โ€บ teabow โ€บ android-csv-reader
GitHub - teabow/android-csv-reader: A simple Android csv reader implementation with annotations
An Android csv reader implementation with annotations ยท From a users.csv file : lastname,fisrtname,city Bryant,Kobe,Los Angeles James,LeBron,Akron Parker,Tony,Paris ยท
Starred by 17 users
Forked by 7 users
Languages ย  Java 100.0% | Java 100.0%
๐ŸŒ
YouTube
youtube.com โ€บ watch
Read CSV File From assets in Android Kotlin || In Just 3 Steps. - YouTube
#android #androidtutorialsHello Everyone I hope you all are doing good.Today we are doing to explore Pinterest Bottom Navigation UI in Android. Watch the Vid...
Published ย  April 28, 2021