How to read a previously built-in CSV file in the android app?

Asked

Viewed 95 times

0

I’m having difficulties in getting this part , I’ve followed all the steps of various sites, I reach the end and the application reads the file. Does anyone know what might be happening??

  • 2

    Improve your question by adding the part of the code where you have difficulty getting to the desired result.

  • 2

    Welcome to the community. Since you are new here, I recommend that you do the [tour] and read the [Ask] guide. As it stands, your question is not clear enough and may be closed. You can [Edit] your question by adding more details of what you did - and what you didn’t do -, as well as putting the source code related to the problem; try to create a [mcve] demonstrating the situation as well. By doing so, you’ll be able to keep the question open and, most importantly, get easier help.

1 answer

1

Good afternoon Leandro,

I found this article that may be relevant:

https://stackoverflow.com/questions/8499351/how-to-read-csv-file-in-android

The following code will be the answer given as correct:

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;

}

I hope I’ve helped.

  • 2

    Thank you colleague and continuation of good work

  • 2

    This link may be a good suggestion, but your reply will not be valid if one day the link crashes. In addition, it is important for the community to have content right here on the site. It would be better to include more details in your response. A summary of the content of the link would be helpful enough! Learn more about it in this item of our Community FAQ: We want answers that contain only links?

  • 1

    I already amended the post, thanks for the indication, I had not thought about it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.