TableReader, Iterable<Object[]>, Iterator<Object[]>public class CSVReader extends AbstractStreamTableReader
Use this reader if you want to load a CSV file by creating a File
and passing it to the constructor.
Example:
java.io.File f = new java.io.File("csv-test.csv");
CSVReader in = new CSVReader(f);
while (in.hasNext()) {
Object columns[] = in.next();
// Do something here
}
in.close();
| Constructor | Description |
|---|---|
CSVReader() |
Default constructor.
|
CSVReader(File file) |
Creates a new instance of CSVReader.
|
CSVReader(InputStream in) |
Creates a new instance of CSVReader.
|
CSVReader(Reader in) |
Deprecated.
Use
CSVReader(InputStream) instead. |
CSVReader(String file) |
Creates a new instance of CSVReader.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Closes the underlying stream.
|
protected static void |
debug(int idx,
String[] o) |
Debugs a string array at standard output stream.
|
String |
getColumnDelimiter() |
Returns the column delimiter to be used.
|
char |
getColumnSeparator() |
Returns the column separator to be used.
|
String |
getCommentChars() |
Returns the characters that will be regarded as comment starters in first position of a line.
|
protected BufferedReader |
getReader() |
Returns the underlying reader.
|
boolean |
hasNext() |
Returns true if there is another CSV row to be read.
|
protected boolean |
isCommentChar(char c) |
Checks whether given character is a comment character
|
protected boolean |
isDelimiter(char c) |
Checks if character is a delimiter character.
|
boolean |
isIgnoreComments() |
Returns whether comment lines will be ignored.
|
boolean |
isIgnoreEmptyLines() |
Returns whether empty lines in a stream will be ignored.
|
protected boolean |
isLineSeparator(char c) |
Checks if character is a line separator.
|
protected boolean |
isSeparator(char c) |
Returns true if character is a separator char.
|
protected boolean |
isSpace(char c) |
Returns true if character is a space char.
|
Object[] |
next() |
Returns next row.
|
protected void |
readHeaderRow() |
Reads the header row from next line.
|
void |
reset() |
Resets the underlying reader.
|
void |
setColumnDelimiter(String s) |
Sets the column delimiters to be used.
|
void |
setColumnSeparator(char s) |
Sets the column separator to be used.
|
void |
setCommentChars(String commentChars) |
Sets the characters used to start comment lines.
|
void |
setIgnoreComments(boolean ignoreComments) |
Controls whether comment lines will be ignored or not.
|
void |
setIgnoreEmptyLines(boolean ignoreEmptyLines) |
Set ignoring of empty lines.
|
createInputStreamReader, createReader, getCharsetDecoder, getInputStream, remove, setCharset, setCharset, setCharsetDecoder, setInputStreamaddCommentCallBack, convert, convert, convertArray, convertArray, get, getColumnIndex, getColumnType, getHeaderRow, getLineCount, getMinimumColumnCount, getRowCount, getTypeConversionHandler, hasHeaderRow, incrementLineCount, incrementRowCount, isHeaderRowRead, iterator, notifyComment, open, registerCommentCallBack, registerTypeConversionHandler, removeCommentCallBack, setColumnType, setHasHeaderRow, setHeaderRow, setHeaderRowRead, setMinimumColumnCount, unregisterCommentCallBack, unregisterTypeConversionHandlerforEach, spliteratorforEachRemainingpublic CSVReader()
public CSVReader(InputStream in)
in - the object delivering the CSV stream.@Deprecated public CSVReader(Reader in)
CSVReader(InputStream) instead.in - the reader object delivering the CSV stream.public CSVReader(File file) throws FileNotFoundException
file - CSV file to read fromFileNotFoundException - - when the file could not be found.public CSVReader(String file) throws FileNotFoundException
file - CSV file to read fromFileNotFoundException - - when the file could not be found.public void close()
close in interface TableReaderclose in class AbstractStreamTableReaderAbstractStreamTableReader.close()protected BufferedReader getReader()
getReader in class AbstractStreamTableReaderAbstractStreamTableReader.getReader()public void reset()
reset in interface TableReaderreset in class AbstractStreamTableReaderAbstractStreamTableReader.reset()public void setColumnDelimiter(String s)
s - new delimiter stringpublic String getColumnDelimiter()
public void setColumnSeparator(char s)
s - new separator characterpublic char getColumnSeparator()
public boolean isIgnoreComments()
AbstractTableReader.notifyComment(String, int, int).public void setIgnoreComments(boolean ignoreComments)
ignoreComments - whether comment lines should be ignoredpublic String getCommentChars()
public void setCommentChars(String commentChars)
commentChars - String that contains all characters for comment startpublic boolean isIgnoreEmptyLines()
public void setIgnoreEmptyLines(boolean ignoreEmptyLines)
ignoreEmptyLines - controls whether empty lines will be ignored.protected boolean isCommentChar(char c)
c - character to checkprotected boolean isSeparator(char c)
c - character to checkprotected boolean isSpace(char c)
c - character to checkprotected boolean isDelimiter(char c)
c - character to check.protected boolean isLineSeparator(char c)
c - character to check.public boolean hasNext()
public Object[] next()
AbstractTableReader.getMinimumColumnCount().protected void readHeaderRow()
readHeaderRow in class AbstractTableReaderAbstractTableReader.readHeaderRow()protected static void debug(int idx,
String[] o)
idx - row indexo - string array to debugCopyright © 2018. All rights reserved.