public class CSV extends Object
CSVReader and CSVWriter objects.
Also it provides helper methods to read and write CSV. Example: // define CSV format
CSV csv = CSV
.separator(',')
.skipLines(1)
.create();
// write CSV file
csv.write("example.csv", new CSVWriteProc() {
public void process(CSVWriter out) {
out.writeNext("Col1", "Col2");
out.writeNext("Val1", "Val2");
}
});
// read CSV file
csv.read("example.csv", new CSVReadProc() {
public void procRow(int rowIndex, String... values) {
System.out.println(Arrays.asList(values));
}
});| Modifier and Type | Class and Description |
|---|---|
static class |
CSV.Builder
A builder for creating CSV formats.
|
| Modifier and Type | Method and Description |
|---|---|
static CSV.Builder |
charset(Charset charset)
Constructs
CSVBuilder with specified charset |
static CSV.Builder |
charset(String charsetName)
Constructs
CSVBuilder with specified charset |
static CSV |
create()
Constructs
CSV using default separator, quote char, etc. |
static CSV.Builder |
escape(char escapeChar)
Constructs
CSVBuilder with specified escapeChar |
static CSV.Builder |
ignoreLeadingWhiteSpace()
Constructs
CSVBuilder. |
static CSV.Builder |
lineEnd(String lineEnd)
Constructs
CSVBuilder with specified line terminator |
static CSV.Builder |
noEscape()
Constructs
CSVBuilder with no escape char |
static CSV.Builder |
noQuote()
Constructs
CSVBuilder with no quote char |
static CSV.Builder |
notIgnoreLeadingWhiteSpace()
Constructs
CSVBuilder. |
static CSV.Builder |
notStrictQuotes()
Constructs
CSVBuilder. |
static CSV.Builder |
quote(char quoteChar)
Constructs
CSVBuilder with specified quoteChar |
void |
read(CSVReader reader,
CSVReadProc proc)
Read CSV using the supplied
CSVReadProc. |
void |
read(File file,
CSVReadProc proc)
Read CSV using the supplied
CSVReadProc. |
void |
read(InputStream is,
CSVReadProc proc)
Read CSV using the supplied
CSVReadProc. |
void |
read(Reader reader,
CSVReadProc proc)
Read CSV using the supplied
CSVReadProc. |
void |
read(String fileName,
CSVReadProc proc)
Read CSV using the supplied
CSVReadProc. |
void |
readAndClose(CSVReader reader,
CSVReadProc proc)
Read CSV using the supplied
CSVReadProc. |
void |
readAndClose(InputStream is,
CSVReadProc proc)
Read CSV using the supplied
CSVReadProc. |
void |
readAndClose(Reader reader,
CSVReadProc proc)
Read CSV using the supplied
CSVReadProc. |
CSVReader |
reader(File file)
Constructs
CSVReader using configured CSV format. |
CSVReader |
reader(InputStream is)
Constructs
CSVReader using configured CSV format. |
CSVReader |
reader(Reader reader)
Constructs
CSVReader using configured CSV format. |
CSVReader |
reader(String fileName)
Constructs
CSVReader using configured CSV format. |
static CSV.Builder |
separator(char separator)
Constructs
CSVBuilder with specified separator |
static CSV.Builder |
skipLines(int skipLines)
Constructs
CSVBuilder with specified number of lines to skip for start reading |
static CSV.Builder |
strictQuotes()
Constructs
CSVBuilder. |
void |
write(CSVWriter writer,
CSVWriteProc proc)
Write CSV using the supplied
CSVWriteProc. |
void |
write(File file,
CSVWriteProc proc)
Write CSV using the supplied
CSVWriteProc. |
void |
write(OutputStream os,
CSVWriteProc proc)
Write CSV using the supplied
CSVWriteProc. |
void |
write(String fileName,
CSVWriteProc proc)
Write CSV using the supplied
CSVWriteProc. |
void |
write(Writer writer,
CSVWriteProc proc)
Write CSV using the supplied
CSVWriteProc. |
void |
writeAndClose(CSVWriter writer,
CSVWriteProc proc)
Write CSV using the supplied
CSVWriteProc. |
void |
writeAndClose(OutputStream os,
CSVWriteProc proc)
Write CSV using the supplied
CSVWriteProc. |
void |
writeAndClose(Writer writer,
CSVWriteProc proc)
Write CSV using the supplied
CSVWriteProc. |
CSVWriter |
writer(File file)
Constructs
CSVWriter using configured CSV file format. |
CSVWriter |
writer(OutputStream os)
Constructs
CSVWriter using configured CSV file format. |
CSVWriter |
writer(String fileName)
Constructs
CSVWriter using configured CSV file format. |
CSVWriter |
writer(Writer writer)
Constructs
CSVWriter using configured CSV format. |
public CSVWriter writer(Writer writer)
CSVWriter using configured CSV format.writer - the writer to an underlying CSV.public CSVWriter writer(OutputStream os)
CSVWriter using configured CSV file format.os - the output stream to an underlying CSV.public CSVWriter writer(File file)
CSVWriter using configured CSV file format.file - CSV filepublic CSVWriter writer(String fileName)
CSVWriter using configured CSV file format.fileName - name of CSV filepublic void write(Writer writer, CSVWriteProc proc)
CSVWriteProc.writer - the writer to an underlying CSV. The writer will not be closed.proc - the CSVWriteProc to use for CSV writingpublic void write(OutputStream os, CSVWriteProc proc)
CSVWriteProc.os - the output stream to an underlying CSV. The output stream will not be closed.proc - the CSVWriteProc to use for CSV writingpublic void write(String fileName, CSVWriteProc proc)
CSVWriteProc.fileName - the name of CSV fileproc - the CSVWriteProc to use for CSV writingpublic void write(CSVWriter writer, CSVWriteProc proc)
CSVWriteProc.writer - the writer to an underlying CSV. The writer will not be closed.proc - the CSVWriteProc to use for CSV writingpublic void write(File file, CSVWriteProc proc)
CSVWriteProc.file - CSV fileproc - the CSVWriteProc to use for CSV writingpublic void writeAndClose(Writer writer, CSVWriteProc proc)
CSVWriteProc.writer - the writer to an underlying CSV. The writer will be closed.proc - the CSVWriteProc to use for CSV writingpublic void writeAndClose(OutputStream os, CSVWriteProc proc)
CSVWriteProc.os - the output stream to an underlying CSV. The output stream will be closed.proc - the CSVWriteProc to use for CSV writingpublic void writeAndClose(CSVWriter writer, CSVWriteProc proc)
CSVWriteProc.writer - the writer to an underlying CSV. The writer will be closed.proc - the CSVWriteProc to use for CSV writingpublic CSVReader reader(Reader reader)
CSVReader using configured CSV format.reader - the reader of an underlying CSV.public CSVReader reader(InputStream is)
CSVReader using configured CSV format.is - the input stream of an underlying CSV.public CSVReader reader(File file)
CSVReader using configured CSV format.file - the CSV filepublic CSVReader reader(String fileName)
CSVReader using configured CSV format.fileName - the file name.public void read(InputStream is, CSVReadProc proc)
CSVReadProc.is - the input stream of an underlying CSV. The input stream will not be closed.proc - the CSVReadProc to use for CSV readingpublic void read(Reader reader, CSVReadProc proc)
CSVReadProc.reader - the reader of an underlying CSV. The reader will not be closed.proc - the CSVReadProc to use for CSV readingpublic void read(File file, CSVReadProc proc)
CSVReadProc.file - CSV fileproc - the CSVReadProc to use for CSV readingpublic void read(String fileName, CSVReadProc proc)
CSVReadProc.fileName - the file nameproc - the CSVReadProc to use for CSV readingpublic void read(CSVReader reader, CSVReadProc proc)
CSVReadProc.reader - the reader of an underlying CSV. The reader will not be closed.proc - the CSVReadProc to use for CSV readingpublic void readAndClose(InputStream is, CSVReadProc proc)
CSVReadProc.is - the input stream of an underlying CSV. The input stream will be closed.proc - the CSVReadProc to use for CSV readingpublic void readAndClose(Reader reader, CSVReadProc proc)
CSVReadProc.reader - the reader of an underlying CSV. The reader will be closed.proc - the CSVReadProc to use for CSV readingpublic void readAndClose(CSVReader reader, CSVReadProc proc)
CSVReadProc.reader - the reader of an underlying CSV. The reader will be closed.proc - the CSVReadProc to use for CSV readingpublic static CSV create()
CSV using default separator, quote char, etc.public static CSV.Builder separator(char separator)
CSVBuilder with specified separatorseparator - the delimiter to use for separating entriespublic static CSV.Builder quote(char quoteChar)
CSVBuilder with specified quoteCharquoteChar - the character to use for quoted elementspublic static CSV.Builder noQuote()
CSVBuilder with no quote charpublic static CSV.Builder escape(char escapeChar)
CSVBuilder with specified escapeCharescapeChar - the character to use for escaping quotechars or escapecharspublic static CSV.Builder noEscape()
CSVBuilder with no escape charpublic static CSV.Builder lineEnd(String lineEnd)
CSVBuilder with specified line terminatorlineEnd - the line feed terminator to usepublic static CSV.Builder skipLines(int skipLines)
CSVBuilder with specified number of lines to skip for start readingskipLines - the line number to skip for start readingpublic static CSV.Builder strictQuotes()
CSVBuilder. Characters outside the quotes will be ignored.public static CSV.Builder notStrictQuotes()
CSVBuilder. Characters outside the quotes will not be ignored.public static CSV.Builder ignoreLeadingWhiteSpace()
CSVBuilder. White space before a quote in a field will be ignored.public static CSV.Builder notIgnoreLeadingWhiteSpace()
CSVBuilder. White space before a quote in a field will not be ignored.public static CSV.Builder charset(Charset charset)
CSVBuilder with specified charsetpublic static CSV.Builder charset(String charsetName)
CSVBuilder with specified charsetCopyright © 2014. All rights reserved.