Skip to main content
added 97 characters in body
Source Link
Jeronimo Backes
  • 6.3k
  • 2
  • 27
  • 31

Use univocity-parsers' ColumnProcessor to do this for you reliably:

CsvParserSettings parserSettings = new CsvParserSettings();

// To get the values of all columns, use a column processor
ColumnProcessor rowProcessor = new ColumnProcessor();
parserSettings.setRowProcessor(rowProcessor);

CsvParser parser = new CsvParser(parserSettings);

//This will kick in our column processor
parser.parse(new FileReader(new File(copyUri)));

//Finally, we can get the column values:
Map<Integer, List<String>> columnValues = rowProcessor.getColumnValuesAsMapOfIndexes();

Clean, faster and easier than doing it by hand. This will handle situations such as rows with different number of columns and add null to the list instead of throwing exceptions at you.

Disclosure: I am the author of this library. It's open-source and free (Apache V2.0 license).

Use univocity-parsers' ColumnProcessor to do this for you reliably:

CsvParserSettings parserSettings = new CsvParserSettings();

// To get the values of all columns, use a column processor
ColumnProcessor rowProcessor = new ColumnProcessor();
parserSettings.setRowProcessor(rowProcessor);

CsvParser parser = new CsvParser(parserSettings);

//This will kick in our column processor
parser.parse(new FileReader(new File(copyUri)));

//Finally, we can get the column values:
Map<Integer, List<String>> columnValues = rowProcessor.getColumnValuesAsMapOfIndexes();

Clean, faster and easier than doing it by hand. This will handle situations such as rows with different number of columns and add null to the list instead of throwing exceptions at you.

Use univocity-parsers' ColumnProcessor to do this for you reliably:

CsvParserSettings parserSettings = new CsvParserSettings();

// To get the values of all columns, use a column processor
ColumnProcessor rowProcessor = new ColumnProcessor();
parserSettings.setRowProcessor(rowProcessor);

CsvParser parser = new CsvParser(parserSettings);

//This will kick in our column processor
parser.parse(new FileReader(new File(copyUri)));

//Finally, we can get the column values:
Map<Integer, List<String>> columnValues = rowProcessor.getColumnValuesAsMapOfIndexes();

Clean, faster and easier than doing it by hand. This will handle situations such as rows with different number of columns and add null to the list instead of throwing exceptions at you.

Disclosure: I am the author of this library. It's open-source and free (Apache V2.0 license).

Source Link
Jeronimo Backes
  • 6.3k
  • 2
  • 27
  • 31

Use univocity-parsers' ColumnProcessor to do this for you reliably:

CsvParserSettings parserSettings = new CsvParserSettings();

// To get the values of all columns, use a column processor
ColumnProcessor rowProcessor = new ColumnProcessor();
parserSettings.setRowProcessor(rowProcessor);

CsvParser parser = new CsvParser(parserSettings);

//This will kick in our column processor
parser.parse(new FileReader(new File(copyUri)));

//Finally, we can get the column values:
Map<Integer, List<String>> columnValues = rowProcessor.getColumnValuesAsMapOfIndexes();

Clean, faster and easier than doing it by hand. This will handle situations such as rows with different number of columns and add null to the list instead of throwing exceptions at you.