public class CSVFileReader extends CSVFile
Adapted from a C++ original that is Copyright (C) 1999 Lucent Technologies.
Excerpted from 'The Practice of Programming' by Brian Kernighan and Rob Pike.
Included by permission of the Addison-Wesley web site, which says: "You may use this code for any purpose, as long as you leave the copyright notice and book citation attached".
Modifier and Type | Field and Description |
---|---|
protected BufferedReader |
in
The buffered reader linked to the CSV file to be read.
|
DEFAULT_FIELD_SEPARATOR, DEFAULT_TEXT_QUALIFIER, fieldSeparator, textQualifier
Constructor and Description |
---|
CSVFileReader(String inputFileName)
CSVFileReader constructor just need the name of the existing CSV file
that will be read.
|
CSVFileReader(String inputFileName,
char sep)
CSVFileReader constructor with a given field separator.
|
CSVFileReader(String inputFileName,
char sep,
char qual)
CSVFileReader constructor with given field separator and text qualifier.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the input CSV file.
|
protected int |
handlePlainField(String s,
StringBuffer sb,
int i)
Handles an unquoted field.
|
protected int |
handleQuotedField(String s,
StringBuffer sb,
int i)
Handles a quoted field.
|
Vector<String> |
readFields()
Split the next line of the input CSV file into fields.
|
getFieldSeparator, getTextQualifier, setFieldSeparator, setTextQualifier
protected BufferedReader in
public CSVFileReader(String inputFileName) throws FileNotFoundException, UnsupportedEncodingException
inputFileName
- The name of the CSV file to be opened for readingFileNotFoundException
- If the file to be read does not existUnsupportedEncodingException
public CSVFileReader(String inputFileName, char sep) throws FileNotFoundException, UnsupportedEncodingException
inputFileName
- The name of the CSV file to be opened for readingsep
- The field separator to be used; overwrites the default oneFileNotFoundException
- If the file to be read does not existUnsupportedEncodingException
public CSVFileReader(String inputFileName, char sep, char qual) throws FileNotFoundException, UnsupportedEncodingException
inputFileName
- The name of the CSV file to be opened for readingsep
- The field separator to be used; overwrites the default onequal
- The text qualifier to be used; overwrites the default oneFileNotFoundException
- If the file to be read does not existUnsupportedEncodingException
public Vector<String> readFields() throws IOException
This is currently the most important function of the package.
IOException
- If an error occurs while reading the new line from
the filepublic void close() throws IOException
IOException
- If an error occurs while closing the fileprotected int handleQuotedField(String s, StringBuffer sb, int i)
protected int handlePlainField(String s, StringBuffer sb, int i)
Copyright © 2008-2014 Logical Objects. All Rights Reserved.