|
Copyright © 2008-2011 Ralph Schuster. All Rights Reserved. | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcsv.impl.AbstractTableReader
csv.impl.AbstractStreamTableReader
csv.impl.CSVReader
public class CSVReader
Reads from CSV like streams.
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 Summary | |
|---|---|
CSVReader()
Default constructor. |
|
CSVReader(java.io.File file)
Creates a new instance of CSVReader. |
|
CSVReader(java.io.InputStream in)
Creates a new instance of CSVReader. |
|
CSVReader(java.io.Reader in)
Deprecated. Use CSVReader(InputStream) instead. |
|
CSVReader(java.lang.String file)
Creates a new instance of CSVReader. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the underlying stream. |
protected static void |
debug(int idx,
java.lang.String[] o)
Debugs a string array at standard output stream. |
java.lang.String |
getColumnDelimiter()
Returns the column delimiter to be used. |
char |
getColumnSeparator()
Returns the column separator to be used. |
java.lang.String |
getCommentChars()
Returns the characters that will be regarded as comment starters in first position of a line. |
protected java.io.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. |
java.lang.Object[] |
next()
Returns next row. |
protected void |
readHeaderRow()
Reads the header row from next line. |
void |
reset()
Resets the underlying reader. |
void |
setColumnDelimiter(java.lang.String s)
Sets the column delimiters to be used. |
void |
setColumnSeparator(char s)
Sets the column separator to be used. |
void |
setCommentChars(java.lang.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. |
| Methods inherited from class csv.impl.AbstractStreamTableReader |
|---|
getInputStream, remove, setInputStream |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CSVReader()
public CSVReader(java.io.InputStream in)
in - the object delivering the CSV stream.@Deprecated public CSVReader(java.io.Reader in)
CSVReader(InputStream) instead.
in - the reader object delivering the CSV stream.
public CSVReader(java.io.File file)
throws java.io.FileNotFoundException
file - CSV file to read from
java.io.FileNotFoundException - - when the file could not be found.
public CSVReader(java.lang.String file)
throws java.io.FileNotFoundException
file - CSV file to read from
java.io.FileNotFoundException - - when the file could not be found.| Method Detail |
|---|
public void close()
close in interface TableReaderclose in class AbstractStreamTableReaderAbstractStreamTableReader.close()protected java.io.BufferedReader getReader()
getReader in class AbstractStreamTableReaderAbstractStreamTableReader.getReader()public void reset()
reset in interface TableReaderreset in class AbstractStreamTableReaderAbstractStreamTableReader.reset()public void setColumnDelimiter(java.lang.String s)
s - new delimiter stringpublic java.lang.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 java.lang.String getCommentChars()
public void setCommentChars(java.lang.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 check
protected boolean isSeparator(char c)
c - character to check
protected boolean isSpace(char c)
c - character to check
protected boolean isDelimiter(char c)
c - character to check.
protected boolean isLineSeparator(char c)
c - character to check.
public boolean hasNext()
public java.lang.Object[] next()
AbstractTableReader.getMinimumColumnCount().
protected void readHeaderRow()
readHeaderRow in class AbstractTableReaderAbstractTableReader.readHeaderRow()
protected static void debug(int idx,
java.lang.String[] o)
idx - row indexo - string array to debug
|
Copyright © 2008-2011 Ralph Schuster. All Rights Reserved. | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||