public class CsvWriter
extends java.lang.Object
implements java.io.Closeable
Writer
to allow easy
writing of lines of data with fields separated by a particular string.
Despite the name of the class, any single character may be used as the
separator.Constructor and Description |
---|
CsvWriter(java.io.Writer writer)
Creates a new CSV writer which will write to the specified writer
using a comma as the field separator.
|
CsvWriter(java.io.Writer writer,
java.lang.String separator)
Creates a new CSV writer which will write to the specified writer
and separate fields with the specified string.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the underlying writer supplied to this CSV writer's constructor.
|
void |
writeCsv(java.lang.Object... objects)
Writes a line to the writer provided to the constructor.
|
public CsvWriter(java.io.Writer writer, java.lang.String separator)
writer
- the writer to which to writeseparator
- the separator which will be placed between the fields.
It must be one character long.java.lang.NullPointerException
- if either of the arguments is null
java.lang.IllegalArgumentException
- if the length of the separator is
not 1public CsvWriter(java.io.Writer writer)
writer
- writer the writer to which to writejava.lang.NullPointerException
- if writer
is null
public void writeCsv(java.lang.Object... objects) throws java.io.IOException
java.util.List
, each of its
members will be written as an individual field (i.e. the list will
be automatically unpacked).objects
- the objects to writejava.io.IOException
- if an I/O error occurs during writingpublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if an I/O error occurs