Rather than reinventing the wheel you could have a look at OpenCSV which supports reading and writing of CSV files. Here are examples of reading & writing


Please consider Apache commons csv. To fast understand the api, there are four important classes:

CSVFormat

Specifies the format of a CSV file and parses input.

CSVParser

Parses CSV files according to the specified format.

CSVPrinter

Prints values in a CSV format.

CSVRecord

A CSV record parsed from a CSV file.

Code Example: enter image description here

Unit test code: enter image description here