public class CSVWriter extends Object implements Closeable
By default ; is used to separate columns and line breaks are used to separate rows. If a column value contains the separator character or a line break, it is quoted using ".
If the quotation character occurs withing an already quoted string, it is escaped using \. If no quotation charater is specified (set to \0), the escape character is used if possible. If quoting or escaping is required but disabled (using \0 for their respective value), an exception will be thrown as no valid output can be generated.
Constructor and Description |
---|
CSVWriter(Writer writer)
Creates a new writer sending data to the given writer.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
CSVWriter |
withEscape(char escape)
Specifies the escape character to use.
|
CSVWriter |
withInputTrimming(boolean trim)
Controls if each added cell value of the type String should be trimmed or not
By default this is true.
|
CSVWriter |
withQuotation(char quotation)
Specifies the quotation character to use.
|
CSVWriter |
withSeparator(char separator)
Specifies the separator character to use.
|
CSVWriter |
writeArray(Object... row)
Writes the given array of values as row.
|
CSVWriter |
writeList(List<Object> row)
Writes the given list of values as row.
|
public CSVWriter withSeparator(char separator)
By default this is ;.
separator
- the separator to usepublic CSVWriter withQuotation(char quotation)
By default this is ". Use \0 to disable quotation entirely. Note that quotation is required if columns contain the separator character or a line break.
quotation
- the quotation character to usepublic CSVWriter withEscape(char escape)
By default this is \. Use \0 to disable escaping entirely. Note that escaping is required if columns contain a quotation character inside an already quoted column. Or if values contain the separator character and no quotation is possible (quotation character is \0).
escape
- the escape character to usepublic CSVWriter withInputTrimming(boolean trim)
By default this is true. Use false if strings should not be trimmed.
trim
- the value controlling if strings should be trimmedpublic CSVWriter writeList(List<Object> row) throws IOException
row
- the data to write. null values will be completely skipped.IOException
- in case of an IO error when writing to the underlying writerpublic CSVWriter writeArray(Object... row) throws IOException
row
- the data to writeIOException
- in case of an IO error when writing to the underlying writerpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2018. All rights reserved.