#Implementing a BufferedReader, works fine, just want to understand what this code means.

5 messages · Page 1 of 1 (latest)

rough widget
#

Hopefully this snippet is enough context. I am reading from a simple CSV to store data. I'm just wondering what this bit of code is saying especially the add(line.split(",") I assume it has something to do with the comma separation in the CSV but I just want to understand the code better and not simply use it.

try (BufferedReader br = new BufferedReader(new FileReader(file))) {

    String line = "";
    while ((line = br.readLine()) != null) {

            listRecord.add(line.split(","));
      
    }

Thanks for any insight!

gaunt robinBOT
#

This post has been reserved for your question.

Hey @rough widget! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

regal trellis
#

You are essentially creating a new BufferedReader that is looping through a file and reading each line. Each line contains objects separated by ,'s which contains different objects. listRecord adds each of these String[] to what looks like an ArrayList or Set

rough widget
#

Thank you! So the line.split(",") is just a way to mark where each element ends in the CSV? In theory I could make it a different character if my elements were separated by a different character?