如何在Android的读取csv文件?文件、如何在、Android、csv

2023-09-12 08:18:21 作者:眉蹙秋波

可能重复:   获取和Android的解析CSV文件

Possible Duplicate: Get and Parse CSV file in android

我想保存在Android应用程序本身和放大器csv文件;它应该被称为读取和放大器;后来根据requirements.I打印值一定要CSV文件要在应用程序中都没有请外部的应用程序[SD卡]在这。任何例子将是真正helpful.Thanks

I would like to store a csv file in android app itself & it should be called for read & later print the values according to the requirements.I definitely want the csv file to be called inside the app not outside the app[SD Card].Any examples on this will be really helpful.Thanks

推荐答案

我有这样的事情;

public final List<String[]> readCsv(Context context) {
  List<String[]> questionList = new ArrayList<String[]>();
  AssetManager assetManager = context.getAssets();

  try {
    InputStream csvStream = assetManager.open(CSV_PATH);
    InputStreamReader csvStreamReader = new InputStreamReader(csvStream);
    CSVReader csvReader = new CSVReader(csvStreamReader);
    String[] line;

    // throw away the header
    csvReader.readNext();

    while ((line = csvReader.readNext()) != null) {
      questionList.add(line);
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
  return questionList;
}