how to use .csv file in android?

前端 未结 4 1026
忘了有多久
忘了有多久 2021-01-07 15:36

I\'m doing a sample Quiz application in Android. I used array to store the Questions and Answers, now I wish to store the questions and answers in a .csv file.

4条回答
  •  执念已碎
    2021-01-07 15:40

    Put you .csv in the assert folder and access it as follow

    I was using .csv to get the list of counter in my application..

    public  ArrayList COUNTRIES     = new ArrayList();
        try {
    
                    is = res.getAssets().open("country.csv");
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    String line;
                    while ((line = reader.readLine()) != null) 
                         COUNTRIES.add(line);
    
                    }
                    catch (IOException ex) {
                        // handle exception
                    }
                    finally {
                        try {
                            is.close();
                        }
                        catch (IOException e) {
                            // handle exception
                        }
                    }
    

提交回复
热议问题