I'm initially looking at using Apache Common's csv library's CSVPrinter, and it provides different record separator choices. Either \n
, \r
or \r\n
. Or I could just set using System.lineSeparator()
. However, this is just honoring the line separator convention on the producer platform. My concern is, if I do not have control on what the consumer platform and language they choose from, how do I minimize the risk of a consumer erroneously read \r
into their parsing record? For example, if consumer is in C++ using getline() to read a new line.
Is it safe to always just specify only \n
as the record separator on the producer part? Would any program on a windows/dos platform then consume and recognize the line changes properly? If I just use java's own BufferedWriter.newLine()
would the same problem still exist? (in that it's writing whatever line separator on the producer system but has no control how consumer will perceive it)?
If just using \n
is the safest thing to do, I'm not sure why it seems the most prevalent CSVFormat being used (or so I thought?) in apache commons csv is still setting recordseparator to \r\n
, in both DEFAULT and EXCEL format?