0

I am reading a CSV file and using OpenCSV to read it and CircularFifoBuffer to split the data into columns and assign the value from each column to a string. This works fine for reading a specific row in the csv file, however I wish to read the csv file line by line starting at the beginning and working downwards to the final row.

Then each time a row is read the string values will be compared and provided a given condition is satisfied the next row will be read.

I can handle all of the above bar processing the CSV data line by line.

Any pointers would be greatly appreciated.

user
  • 158
  • 6
  • 19

1 Answers1

2

Directly from the FAQ:

If you want to use an Iterator style pattern, you might do something like this:

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
    // nextLine[] is an array of values from the line
    System.out.println(nextLine[0] + nextLine[1] + "etc...");
}

Or, if you might just want to slurp the whole lot into a List, just call readAll()...

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
List myEntries = reader.readAll();

which will give you a List of String[] that you can iterate over. If all else fails, check out the Javadoc.

Todd
  • 30,472
  • 11
  • 81
  • 89
  • So your suggesting to read each line and import it into the FifoBuffer, process it and then move to the next line? – user Jan 10 '15 at 14:42