public class CSVReader extends Object
| Modifier and Type | Field and Description |
|---|---|
static char |
NO_QUOTS |
| Constructor and Description |
|---|
CSVReader(Reader r)
convenience Constructor, default to comma separator, " for quote, no
multiline fields, with trimming.
|
CSVReader(Reader r,
char separator,
char quote,
boolean allowMultiLineFields,
boolean trim)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the Reader.
|
String |
get()
Read one field from the CSV file
|
String |
get(int row) |
String |
get(String row) |
String[] |
getAllFieldsInLine()
Get all fields in the line
|
double |
getDouble()
Read one double field from the CSV file.
|
float |
getFloat()
Read one float field from the CSV file.
|
int |
getInt()
Read one integer field from the CSV file
|
int |
getLineCount() |
long |
getLong()
Read one long field from the CSV file
|
String[] |
getRowNames() |
static void |
main(String[] args)
Test driver
|
boolean |
next() |
void |
readHeader(boolean lower) |
void |
skip(int fields)
Skip over fields you don't want to process.
|
void |
skipToNextLine()
Skip over remaining fields on this line you don't want to process.
|
public static final char NO_QUOTS
public CSVReader(Reader r)
r - input Reader source of CSV Fields to read.public CSVReader(Reader r, char separator, char quote, boolean allowMultiLineFields, boolean trim)
r - input Reader source of CSV Fields to read.separator - field separator character, usually ',' in North America, ';'
in Europe and sometimes '\t' for tab.quote - char to use to enclose fields containing a separator, usually
'\"'allowMultiLineFields - true if reader should allow quoted fields to span more than
one line. Microsoft Excel sometimes generates files like this.trim - true if reader should trim lead/trailing whitespace e.g.
blanks, Cr, Lf. Tab off fields.public void close()
throws IOException
IOExceptionpublic String get() throws EOFException, IOException
EOFException - at end of file after all the fields have been read.IOException - Some problem reading the file, possibly malformed data.public String[] getAllFieldsInLine() throws EOFException, IOException
EOFExceptionIOExceptionpublic double getDouble()
throws EOFException,
IOException,
NumberFormatException
EOFException - at end of file after all the fields have been read.IOException - Some problem reading the file, possibly malformed data.NumberFormatException - , if field does not contain a well-formed int.public float getFloat()
throws EOFException,
IOException,
NumberFormatException
EOFException - at end of file after all the fields have been read.IOException - Some problem reading the file, possibly malformed data.NumberFormatException - , if field does not contain a well-formed int.public int getInt()
throws EOFException,
IOException,
NumberFormatException
EOFException - at end of file after all the fields have been read.IOException - Some problem reading the file, possibly malformed data.NumberFormatException - , if field does not contain a well-formed int.public long getLong()
throws EOFException,
IOException,
NumberFormatException
EOFException - at end of file after all the fields have been read.IOException - Some problem reading the file, possibly malformed data.NumberFormatException - , if field does not contain a well-formed int.public void skip(int fields)
throws EOFException,
IOException
fields - How many field you want to bypass reading. The newline counts
as one field.EOFException - at end of file after all the fields have been read.IOException - Some problem reading the file, possibly malformed data.public void skipToNextLine()
throws EOFException,
IOException
EOFException - at end of file after all the fields have been read.IOException - Some problem reading the file, possibly malformed data.public void readHeader(boolean lower)
throws EOFException,
IOException
EOFExceptionIOExceptionpublic String[] getRowNames()
public boolean next()
throws IOException
IOExceptionpublic String get(String row) throws IOException
IOExceptionpublic String get(int row)
public int getLineCount()
public static void main(String[] args)
args - not usedCopyright © 2014. All rights reserved.