TableWriterpublic class CSVWriter extends AbstractStreamTableWriter
Example:
java.io.File f = new java.io.File("csv-test.csv");
CSVWriter out = new CSVWriter(f);
out.printRow(new Object[] { "0:0", "0:1", "0:2" });
out.printRow(new Object[] { "1:0", "1:1", "1:2" });
out.close();
| Constructor | Description |
|---|---|
CSVWriter() |
Default constructor.
|
CSVWriter(File file) |
Constructor for writing into a file.
|
CSVWriter(OutputStream out) |
Constructor for writing into a stream.
|
CSVWriter(Writer out) |
Deprecated.
Use
CSVWriter(OutputStream) instead. |
CSVWriter(Writer out,
boolean flush) |
Deprecated.
|
CSVWriter(String file) |
Constructor for writing into a file.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Closes the underlying stream.
|
protected boolean |
columnNeedsDelimiting(String s) |
Decides if a column value needs to be wrapped with delimiters.
|
int |
getColumnCount() |
Returns the columns written to the stream.
|
String |
getColumnDelimiter() |
Returns the column delimiter to be used.
|
char |
getColumnSeparator() |
Returns the column separator to be used.
|
char |
getCommentChar() |
Returns the character used for indicating comments
|
String |
getRowSeparator() |
Returns the row separator to be used.
|
PrintWriter |
getWriter() |
Returns the underlying stream.
|
protected void |
init() |
Initializes the writer.
|
boolean |
isColumnDelimiterRequired() |
Returns whether column delimiters are always required.
|
protected String |
prepareColumnValue(String s) |
Replaces all occurrences of the delimiter by doubling it.
|
String |
prepareComment(String comment) |
Formats a comment for printing
|
String |
prepareRow(Object[] columns) |
Formats a row for CSV output.
|
void |
printComment(String comment) |
Prints a comment into the CSV stream.
|
void |
printComment(String comment,
int row,
int column) |
Prints a comment into the stream.
|
void |
printRow(Object[] columns) |
Prints a new row into the CSV file.
|
void |
setColumnDelimiter(String s) |
Sets the column delimiter to be used.
|
void |
setColumnDelimiterRequired(boolean b) |
Sets if column separators are always required or not.
|
void |
setColumnSeparator(char s) |
Sets the column separator to be used.
|
void |
setCommentChar(char commentChar) |
Sets the character to be used for indicating comments
|
void |
setRowSeparator(String s) |
Sets the row separator to be used.
|
createOutputStreamWriter, createWriter, getCharsetEncoder, getOutputStream, setCharset, setCharset, setCharsetEncoder, setOutputStreamconvert, convert, getRowCount, getTypeConversionHandler, incrementRowCount, printRow, printRow, printRow, registerTypeConversionHandler, unregisterTypeConversionHandlerpublic CSVWriter()
public CSVWriter(File file) throws IOException
file - fileIOException - when an exception occurspublic CSVWriter(OutputStream out)
out - output streampublic CSVWriter(Writer out)
CSVWriter(OutputStream) instead.out - out writerpublic CSVWriter(Writer out, boolean flush)
out - out writerflush - has no influence and is for compatibility reasons onlypublic CSVWriter(String file) throws IOException
file - fileIOException - when an exception occursprotected void init()
init in class AbstractTableWriterAbstractTableWriter.init()public PrintWriter getWriter()
getWriter in class AbstractStreamTableWriterAbstractStreamTableWriter.getWriter()public void close()
close in interface TableWriterclose in class AbstractStreamTableWriterAbstractStreamTableWriter.close()public void setColumnDelimiter(String s)
isColumnDelimiterRequired().s - the new delimiterpublic String getColumnDelimiter()
public void setColumnSeparator(char s)
s - new separator characterpublic char getColumnSeparator()
public void setRowSeparator(String s)
s - new separatorpublic String getRowSeparator()
public void setColumnDelimiterRequired(boolean b)
b - true when delimiters shall always be written.public boolean isColumnDelimiterRequired()
public char getCommentChar()
public void setCommentChar(char commentChar)
commentChar - the commentChar to setpublic String prepareRow(Object[] columns)
columns - columns to be preparedpublic void printRow(Object[] columns) throws IOException
columns - array of column values.IOException - when an exception occurspublic String prepareComment(String comment)
comment - comment to be printedpublic void printComment(String comment) throws IOException
printComment in interface TableWriterprintComment in class AbstractTableWritercomment - comment to writeIOException - when an exception occurspublic void printComment(String comment, int row, int column) throws IOException
printComment in interface TableWriterprintComment in class AbstractTableWritercomment - comment to writerow - index of row for commentcolumn - index of column for commentIOException - when an exception occursprotected boolean columnNeedsDelimiting(String s)
s - column value to checkprotected String prepareColumnValue(String s)
s - column value to parsepublic int getColumnCount()
Copyright © 2018. All rights reserved.