1

I am working on some code that will take a player name and their shooting percentage from a csvfile and put it into an object that I made called PlayerStat. I am trying to accomplish this by using CSVReaderHeaderAware.

Here is my code:

    for (int i = 0; i < 100; i++){
            Map<String, String> values = new CSVReaderHeaderAware(new FileReader("stats.csv")).readMap();
            String playerName = values.get("Player Name");
            double shootPct = Double.parseDouble(values.get("Percentage"));
            PlayerStat stat = new PlayerStat(playerName, shootPct);
            theArrayList.add(stat);
        }

The first Map is fine and adds to the list perfectly. But, this code just keeps reading the first row of the csv file and I cannot figure out how to keep iterating through the rows in the csv file. Player Name and Percentage are the two columns I would like to go through. Thanks in advance!

WizKid22
  • 23
  • 2
  • 5

1 Answers1

0

This is a guess but try:

CSVReaderHeaderAware reader = new CSVReaderHeaderAware(new FileReader("stats.csv"))
for (int i = 0; i < 100; i++){
        Map<String, String> values = reader.readMap();

There is a probably a close method to be called as well

Bruce Martin
  • 10,358
  • 1
  • 27
  • 38