public class CSVWriter extends Object implements Closeable
| Constructor and Description |
|---|
CSVWriter(Writer writer)
Constructor.
|
CSVWriter(Writer writer,
char delimiter)
Constructor.
|
CSVWriter(Writer writer,
char delimiter,
char comment)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
static String |
escapeCSV(String text)
Escapes a text string for CSV output.
|
static String |
escapeCSV(String text,
char delimiter)
Escapes a text string for CSV output.
|
static void |
escapeCSV(Writer writer,
String text,
char delimiter)
Escapes a text string for CSV output.
|
void |
writeCommentLine(String comment)
Output a CSV comment line.
|
void |
writeDataLine(SortedMap<String,String> fields)
Output the CSV data line which contains the field values
|
void |
writeHeaderLine(SortedMap<String,String> fields)
Output the CSV header line which contains the names of the fields.
|
void |
writeLine(List<String> values)
Output a line of CSV fields.
|
void |
writeLine(String[] values)
Output a line of CSV fields.
|
public CSVWriter(Writer writer)
writer - writer to output topublic CSVWriter(Writer writer, char delimiter)
writer - writer to output todelimiter - field delimiter character to usepublic CSVWriter(Writer writer, char delimiter, char comment)
writer - writer to output todelimiter - field delimiter character to usecomment - comment character to usepublic void writeCommentLine(String comment) throws IOException
Example:
writer.writeCommentLine( "this is a comment" );
results in
# this is a comment line
comment - comment text to output. Embedded newline/carriage returns are handled correctly.IOException - if an error occurs when writingpublic void writeHeaderLine(SortedMap<String,String> fields) throws IOException
fields - fields to outputIOException - if an error occurs when writingpublic void writeDataLine(SortedMap<String,String> fields) throws IOException
fields - fields to outputIOException - if an error occurs when writingpublic void writeLine(List<String> values) throws IOException
values - strings to outputIOException - if an error occurs while writingpublic void writeLine(String[] values) throws IOException
values - strings to outputIOException - if an error occurs while writingpublic static String escapeCSV(String text)
text - text string to escapepublic static String escapeCSV(String text, char delimiter)
text - text string to escapedelimiter - field delimiterpublic static void escapeCSV(Writer writer, String text, char delimiter) throws IOException
text - text string to escapewriter - writer to send the CSV output todelimiter - field delimiter to useIOException - if an IO error occurspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2020. All Rights Reserved.