Non-standard control characters
The CSV specification (section 2.6. of RFC 4180) defines the following control characters:
- Field separator:
,
- Record delimiter:
\r\n
- Field enclosure:
"
FastCSV uses these control characters by default. However, you can change them using the CsvReaderBuilder
or
CsvWriterBuilder
class.
Using non-standard control characters for Read
Section titled “Using non-standard control characters for Read”In the following example, a CSV file with non-standard control characters is read using FastCSV.
import de.siegmar.fastcsv.reader.CsvReader;
/// Example for reading CSV data with control characters that are/// not the default/standard ones.////// FastCSV supports Java 17 and later, but this code uses Java 25/// for brevity, leveraging newer language features.void main() { final String data = """ 'foo';'bar' 'foo2';'bar2' """;
CsvReader.builder() .fieldSeparator(';') .quoteCharacter('\'') .ofCsvRecord(data) .forEach(IO::println);}
You also find this source code example in the FastCSV GitHub repository.
Using non-standard control characters for Write
Section titled “Using non-standard control characters for Write”In the following example, a CSV file with non-standard control characters is created using FastCSV.
import de.siegmar.fastcsv.writer.CsvWriter;import de.siegmar.fastcsv.writer.LineDelimiter;
/// Example for writing CSV data with non-standard control characters.////// FastCSV supports Java 17 and later, but this code uses Java 25/// for brevity, leveraging newer language features.void main() { // The default configuration uses a comma as field separator, // a double quote as quote character and // a CRLF as line delimiter. CsvWriter.builder() .fieldSeparator(';') .quoteCharacter('\'') .lineDelimiter(LineDelimiter.LF) .toConsole() .writeRecord("header1", "header2") .writeRecord("value1", "value;2");}
You also find this source code example in the FastCSV GitHub repository.