Saturday, 1 June 2013

Read csv file in Android

InputStream is = getResources().openRawResource(R.raw.your_csv_file);
     
        try
        {
       
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String line;
       
        while ((line = reader.readLine()) != null )
        {
String [] rowData = line.split(",");

String val1 = rowData[0];
String val2 = rowData[1];

                              //and so on...

    }


        }
        catch (FileNotFoundException e)
        {
// TODO Auto-generated catch block
e.printStackTrace();

        } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

No comments:

Post a Comment