Class CSVWriter
java.lang.Object
ca.phon.csv.CSVWriter
- All Implemented Interfaces:
Closeable,AutoCloseable
Writes data to a CSV file with specified settings.
We escape fields based on the rules defined in RFC4180.
- Author:
- Cristopher Yates
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new CSVWriter with the provided writer and default values for all other options.CSVWriter(Writer writer, char separator, CSVQuoteType quoteType, boolean trimSpaces, boolean unixLineEndings, boolean quoteAllFields) Constructs a new CSVWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(CSVWriterListener listener) Adds a listener to the CSVWriter.voidclose()voidflush()voidWrite the provided data as the next line in a CSV.
-
Constructor Details
-
CSVWriter
Constructs a new CSVWriter with the provided writer and default values for all other options.- Parameters:
writer- The writer for writing the data to a specified file or buffer.
-
CSVWriter
public CSVWriter(Writer writer, char separator, CSVQuoteType quoteType, boolean trimSpaces, boolean unixLineEndings, boolean quoteAllFields) Constructs a new CSVWriter.- Parameters:
writer- The writer for writing the data to a specified file or buffer.separator- The character that will go between the fields.quoteType- The type of quote (single or double) used to surround escaped fields.trimSpaces- Decides whether to trim whitespace from the starts and ends of the fields.unixLineEndings- Decides whether to use Unix line endings (LF) or Windows line endings (CRLF).quoteAllFields- Decides whether to force all fields to be enclosed with quotes.
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
flush
- Throws:
IOException
-
addListener
Adds a listener to the CSVWriter. -
writeNext
Write the provided data as the next line in a CSV.- Parameters:
row- The data to be written as the next row.- Throws:
IOException
-