how to use .csv file in android?

前端 未结 4 1024
忘了有多久
忘了有多久 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:39

    CSV stands for Comma-Separated Values. Quite good explanation can be found at wiki: CSV. Since you're programming on Android platform consider using one of availible Java libraries such as OpenCSV or JavaCSV.

    0 讨论(0)
  • 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<String> COUNTRIES     = new ArrayList<String>();
        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
                        }
                    }
    
    0 讨论(0)
  • 2021-01-07 15:50

    CSV, comma separated values, files are commonly used to transport large amounts of tabular data between either companies or applications that are not directly connected. The files are easily editable using common spreadsheet applications like Microsoft Excel.

    Read more

    And take a look at these Samples on reading / writing *.csv

    .

    0 讨论(0)
  • 2021-01-07 16:02

    I think this is general discussion, (Not specific to android)

    The CSV ("Comma Separated Value") file format is often used to exchange data between disparate applications. The file format, as it is used in Microsoft Excel, has become a pseudo standard throughout the industry, even among non-Microsoft platforms.

    There are many ways to generate a csv file. A csv file is a comma delimited data file. Many applications such as Excel or MS Access allow one to save data in csv format. But you can also generate csv files yourself as long as the data is comma delimited and each line is ended with a line break.

    For more look at Here and For Android use OpenCSV library.

    0 讨论(0)
提交回复
热议问题