uniVocity / univocity-parsers

uniVocity-parsers is a suite of extremely fast and reliable parsers for Java. It provides a consistent interface for handling different file formats, and a solid framework for the development of new parsers.
918 stars 251 forks source link

CsvWriterSettings - add option to not create the final line separator #530

Open ghillert opened 9 months ago

ghillert commented 9 months ago

In Common Format and MIME Type for Comma-Separated Values (CSV) Files it is stated:

The last record in the file may or may not have an ending line break..

Google Sheets that are exported as CSV, do not contain a trailing line break. Also, Google Sheets are exported in a "Windows format" and I need to set setLineSeparator("\r\n") in CsvWriterSettings to create a matching CSV file.

When writing CSV files with univocity, I was trying to recreate the Google Sheets format exactly (to be able to diff CSV files). This does not seem to be (easily) possible right now. I can get somewhat close by setting setNormalizedNewline('\n'), which will not create the last line but it will still create the carriage return character.

Would it be possible to have an option on CsvWriterSettings to set something like setEndingLineSeparator(false)?

This issue may be related to https://github.com/uniVocity/univocity-parsers/issues/388