Thursday 30 August 2012

Read CSV file In Android

    public String[] Read(Context c)
    {
       
           InputStream is = c.getResources().openRawResource (R.raw.list);
           BufferedReader buff= new BufferedReader(new InputStreamReader(is),4*1024);
           int count=0;
             // get the quote as a csv string
             try {
                 String line;
                 while((line=buff.readLine())!=null)
                 {
                    System.out.println(line);
                    StringTokenizer tokenizer = new StringTokenizer(line, ",");
                    id[count]=Integer.toString(count);
                    company[count]=tokenizer.nextToken();
                    symbols[count]=tokenizer.nextToken();
                    from[count]=tokenizer.nextToken();
                    count++;
                 }
               
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    return company;
    }

No comments:

Post a Comment