Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read csv file in android? [duplicate]

Tags:

android

csv

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 requirements.I definitely want the csv file to be called inside the app not outside the app[SD Card].Any examples on this will be really helpful.Thanks

like image 301
Karthik Avatar asked Dec 14 '11 04:12

Karthik


1 Answers

I have something like this;

public final List<String[]> readCsv(Context context) {
  List<String[]> questionList = new ArrayList<String[]>();
  AssetManager assetManager = context.getAssets();

  try {
    InputStream csvStream = assetManager.open(CSV_PATH);
    InputStreamReader csvStreamReader = new InputStreamReader(csvStream);
    CSVReader csvReader = new CSVReader(csvStreamReader);
    String[] line;

    // throw away the header
    csvReader.readNext();

    while ((line = csvReader.readNext()) != null) {
      questionList.add(line);
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
  return questionList;
}
like image 165
Matthew Rudy Avatar answered Oct 08 '22 09:10

Matthew Rudy