You have a number of options. I've used CsvListReader, but you could just as easily use CsvMapReader or CsvBeanReader instead.
You could use the Collector cell processor:
private static final String CSV = "firstName,lastName\nJohn,Dunbar\nBob,Down";
@Test
public final void testCollector() throws IOException {
ICsvListReader reader = new CsvListReader(new StringReader(CSV),
CsvPreference.STANDARD_PREFERENCE);
reader.getHeader(true); // skip header
// Collector processor 'collects' values from a column
List<Object> firstNames = new ArrayList<Object>();
CellProcessor[] processors = {new Collector(firstNames), null};
while(reader.read(processors) != null){
// just keep reading - Collector will collect the values
}
// prints: [John, Bob]
System.out.println(firstNames);
}
Or grab the relevant column after Super CSV has read each line:
@Test
public final void testManual() throws IOException {
ICsvListReader reader = new CsvListReader(new StringReader(CSV),
CsvPreference.STANDARD_PREFERENCE);
reader.getHeader(true); // skip header
List<String> firstNames = new ArrayList<String>();
List<String> line;
while((line = reader.read()) != null){
firstNames.add(line.get(0));
}
// prints: [John, Bob]
System.out.println(firstNames);
}
Either way you'll need to read the whole file - CSV is not a spreadsheet and you can't just grab all of the values in a particular column easily (records can span more than 1 line!). Which brings me to your next question...
Straight from the javadoc:
getLineNumber(): Gets the current position in the file. The first line of the file is line number 1.
getRowNumber(): Gets the current row number (i.e. the number of CSV records - including the header - that have been read). This differs from the lineNumber, which is the number of real lines that have been read in the file. The first row is row 1 (which is typically the header row).