public class CSVFileWriter extends CSVFile
Modifications by Philip R. Burns at Northwestern University.
Modifier and Type | Field and Description |
---|---|
protected java.io.OutputStreamWriter |
outputWriter
Print writer for the CSV file contents.
|
DEFAULT_QUALIFIER, DEFAULT_SEPARATOR, qualifier, separator
Constructor and Description |
---|
CSVFileWriter(java.lang.String outputFileName,
java.lang.String encoding)
Create CSVFileWriter with specified file name and encding,
|
CSVFileWriter(java.lang.String outputFileName,
java.lang.String encoding,
char separator)
Create CSVFileWriter with specified separator character.
|
CSVFileWriter(java.lang.String outputFileName,
java.lang.String encoding,
char separator,
char qualifier)
CSVFileWriter constructor with given field separator and text qualifier.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the output CSV file.
|
java.io.OutputStreamWriter |
getOutputWriter()
Return output writer.
|
protected void |
openOutputFile(java.lang.String outputFileName,
java.lang.String encoding)
Open output file.
|
void |
writeEOL()
Output an end of line.
|
void |
writeFields(java.util.List<?> fields)
Write all fields to a new line in the CSV file.
|
void |
writeFields(java.util.List<?> fields,
int[] indices)
Write selected fields to a new line in the CSV file.
|
void |
writeFields(java.util.List<?> fields,
java.util.List<java.lang.Integer> indices)
Write selected fields to a new line in the CSV file.
|
void |
writeFields(java.lang.Object[] fields)
Write all fields to a new line in the CSV file.
|
void |
writeSeparator()
Output a value separator.
|
void |
writeValue(java.lang.String fieldValue)
Output a value.
|
getQualifier, getSeparator, setQualifier, setSeparator
protected java.io.OutputStreamWriter outputWriter
public CSVFileWriter(java.lang.String outputFileName, java.lang.String encoding) throws java.io.IOException
outputFileName
- Name of CSV file for output.encoding
- Character encoding for file output.java.io.FileNotFoundException
- If file is not found.java.io.IOException
- If an error occurs while writing the file.public CSVFileWriter(java.lang.String outputFileName, java.lang.String encoding, char separator) throws java.io.IOException
outputFileName
- Name of the CSV file to write to.encoding
- Character encoding for file output.separator
- Field separator character.
8java.io.FileNotFoundException
- If file is not found.java.io.IOException
- If an error occurs while writing the file.public CSVFileWriter(java.lang.String outputFileName, java.lang.String encoding, char separator, char qualifier) throws java.io.FileNotFoundException, java.io.IOException
outputFileName
- Name of the CSV file to write to.encoding
- Character encoding for file output.separator
- Field separator.qualifier
- Qualifier character. Ascii 0 means no qualifier.java.io.FileNotFoundException
- If file is not found.java.io.IOException
- If an error occurs while writing the file.protected void openOutputFile(java.lang.String outputFileName, java.lang.String encoding) throws java.io.FileNotFoundException, java.io.IOException
outputFileName
- Name of the CSV file to write to.encoding
- Character encoding for file output.java.io.FileNotFoundException
- If file is not found.java.io.IOException
- If an error occurs while writing the file.public void close() throws java.io.IOException
java.io.IOException
- If an error occurs while closing the file.public void writeValue(java.lang.String fieldValue) throws java.io.IOException
fieldValue
- The field value to output.java.io.IOException
- If an error occurs while closing the file.public void writeFields(java.lang.Object[] fields) throws java.io.IOException
fields
- The array of entries for this line.java.io.IOException
public void writeFields(java.util.List<?> fields) throws java.io.IOException
fields
- The list of entries for this line.java.io.IOException
public void writeFields(java.util.List<?> fields, java.util.List<java.lang.Integer> indices) throws java.io.IOException
fields
- The list of entries for this line.indices
- List of integer indices of entries to output.
The integer "indices" specify which entries to write out, and the order. For example, if "indices" contains the values 3, 4, 1 then entries 3, 4, and 1 from "fields" are written out in that order. Bad indices result in an empty field being output.
java.io.IOException
public void writeFields(java.util.List<?> fields, int[] indices) throws java.io.IOException
fields
- The list of entries for this line.indices
- Array of integer indices of entries to output.
The integer "indices" specify which entries to write out, and the order. For example, if "indices" contains the values 3, 4, 1 then entries 3, 4, and 1 from "fields" are written out in that order. Bad indices result in an empty field being output.
java.io.IOException
public void writeEOL() throws java.io.IOException
java.io.IOException
- If an error occurs while closing the file.public void writeSeparator() throws java.io.IOException
java.io.IOException
- If an error occurs while closing the file.public java.io.OutputStreamWriter getOutputWriter()