如何在Android的读取csv文件? [英] How to read csv file in android?

查看:1237
本文介绍了如何在Android的读取csv文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  获取和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;
}

这篇关于如何在Android的读取csv文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆