public class CSVWriter extends AbstractStreamTableWriter
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 and Description |
|---|
CSVWriter()
Default constructor.
|
CSVWriter(File file)
Constructor for writing into a file.
|
CSVWriter(OutputStream out)
Constructor for writing into a stream.
|
CSVWriter(String file)
Constructor for writing into a file.
|
CSVWriter(Writer out)
Deprecated.
Use
CSVWriter(OutputStream) instead. |
CSVWriter(Writer out,
boolean flush)
Deprecated.
|
| Modifier and Type | Method and 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 streamIOException - when an exception occurspublic CSVWriter(Writer out)
CSVWriter(OutputStream) instead.out - out writerpublic CSVWriter(Writer out, boolean flush)
out - out writerpublic 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 © 2014. All rights reserved.