如何在安卓系统中使用.csv文件?[英] how to use .csv file in android?

本文是小编为大家收集整理的关于如何在安卓系统中使用.csv文件?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在Android中进行示例测验应用程序.我使用数组来存储问题和答案,现在我希望将问题和答案存储在.csv文件中. 可以在Android中解析.csv文件?

推荐答案

CSV代表逗号分隔的值.可以在Wiki上找到相当不错的解释: csv . 由于您是在Android平台上编程的,请考虑使用可用的Java库之一,例如 opencsv javacsv .

其他推荐答案

将.csv放入ostert文件夹中,并如下访问

我正在使用.csv在我的应用程序中获取计数器列表.

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
                    }
                }

其他推荐答案

我认为这是一般讨论,(不是特定于Android)

csv("逗号分隔值")文件格式通常用于在不同的应用程序之间交换数据.文件格式,因为它在Microsoft Excel中使用,已成为整个整个中的伪标准行业,甚至在非Microsoft平台中.

有很多方法可以生成CSV文件. CSV文件是逗号界的数据文件.诸如Excel或MS访问之类的许多应用程序允许一个应用程序以CSV格式保存数据.但是,只要数据是逗号界定的,并且每行都以换行符结束,那么您也可以自己生成CSV文件.

有关更多信息,请查看在这里和Android使用 opencsv 库.

本文地址:https://www.itbaoku.cn/post/102661.html

问题描述

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. it is possible to parse .csv file in Android?

推荐答案

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.

其他推荐答案

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
                    }
                }

其他推荐答案

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.