Package com.logicaldoc.util.csv
Class CSVFileReader
java.lang.Object
com.logicaldoc.util.csv.CSVFile
com.logicaldoc.util.csv.CSVFileReader
- All Implemented Interfaces:
- Closeable,- AutoCloseable
CSVFileReader is a class derived from CSVFile used to parse an existing CSV
 file.
 
 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".
- Version:
- %I%, %G%
- Author:
- Brian Kernighan and Rob Pike (C++ original), Ian F. Darwin (translation into Java and removal of I/O), Ben Ballard (rewrote handleQuotedField to handle double quotes and for readability), Fabrizio Fazzino (added integration with CSVFile, handling of variable textQualifier and Vector with explicit String type)
- 
Constructor SummaryConstructorsConstructorDescriptionCSVFileReader(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.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Close the input CSV file.Split the next line of the input CSV file into fields.Methods inherited from class com.logicaldoc.util.csv.CSVFilegetFieldSeparator, getTextQualifier, setFieldSeparator, setTextQualifier
- 
Constructor Details- 
CSVFileReaderpublic CSVFileReader(String inputFileName) throws FileNotFoundException, UnsupportedEncodingException CSVFileReader constructor just need the name of the existing CSV file that will be read.- Parameters:
- inputFileName- The name of the CSV file to be opened for reading
- Throws:
- FileNotFoundException- If the file to be read does not exist
- UnsupportedEncodingException- If the CSV contains elements not compatible with the UTF-8 encoding
 
- 
CSVFileReaderpublic CSVFileReader(String inputFileName, char sep) throws FileNotFoundException, UnsupportedEncodingException CSVFileReader constructor with a given field separator.- Parameters:
- inputFileName- The name of the CSV file to be opened for reading
- sep- The field separator to be used; overwrites the default one
- Throws:
- FileNotFoundException- If the file to be read does not exist
- UnsupportedEncodingException- If the CSV contains elements not compatible with the UTF-8 encoding
 
- 
CSVFileReaderpublic CSVFileReader(String inputFileName, char sep, char qual) throws FileNotFoundException, UnsupportedEncodingException CSVFileReader constructor with given field separator and text qualifier.- Parameters:
- inputFileName- The name of the CSV file to be opened for reading
- sep- The field separator to be used; overwrites the default one
- qual- The text qualifier to be used; overwrites the default one
- Throws:
- FileNotFoundException- If the file to be read does not exist
- UnsupportedEncodingException- If the CSV contains elements not compatible with the UTF-8 encodings
 
 
- 
- 
Method Details- 
readFieldsSplit the next line of the input CSV file into fields.This is currently the most important function of the package. - Returns:
- Vector of strings containing each field from the next line of the file
- Throws:
- IOException- If an error occurs while reading the new line from the file
 
- 
closeClose the input CSV file.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Throws:
- IOException- If an error occurs while closing the file
 
 
-