Reading CSV file in resources folder android

前端 未结 5 1804
南方客
南方客 2021-01-04 19:39

I am developing an android app in netbeans. I am trying to read CSV file using opencsv. When I put the file in resources folder and try to read it from there, there\'s an er

5条回答
  •  不知归路
    2021-01-04 20:00

    you may use this code

       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();
                  }
    

    you may download csvreader file from http://sourceforge.net/projects/opencsv/files/latest/download

    and import in your project

提交回复
热议问题