如何在android中读取csv文件?

Kar*_*hik 9 csv android

可能重复:
在android中获取并解析CSV文件

我想在Android应用程序本身存储一个csv文件,它应该被调用,然后根据要求打印值.我绝对希望在应用程序内部调用csv文件,而不是在应用程序[SD卡]之外.任何关于此的例子都会非常有用.谢谢

Mat*_*udy 8

我有这样的事情;

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;
}
Run Code Online (Sandbox Code Playgroud)