public class CSVFileReaderProcessor extends Object
The API provides a callback processor interface (CSVLineProcessor)
which is called as the file is processed to receive the CSV header and data lines.
A simpler interface, CSVFieldMapProcessor,
provides the field name and values for each line as an easy to access Map.
Example usage with CSVLineProcessor:
final CSVFileProcessor fp = new CSVFileProcessor();
fp.processFile( "data.csv", new CSVLineProcessor() {
public void processHeaderLine( int linenumber, List<String> fields )
{
// use / save the header
}
public void processDataLine( int linenumber, List<String> fields )
{
// use the data
}
} );
Example usage with CSVFieldMapProcessor:
final CSVFileProcessor fp = new CSVFileProcessor();
fp.processFile( "data.csv", new CSVFieldMapProcessor() {
public void processDataLine( int linenumber, Map<String,String> fields )
{
// use the data
}
} );
| Constructor and Description |
|---|
CSVFileReaderProcessor()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
char |
getComment()
Returns the comment setting.
|
char |
getDelimiter() |
boolean |
isHasHeader()
Indicates if the file has a header line.
|
int |
processFile(String filename,
Charset charset,
CSVFieldMapProcessor processor)
Processes the CSV file using the provided processor.
|
int |
processFile(String filename,
Charset charset,
CSVLineProcessor processor)
Processes the CSV file using the provided processor
|
int |
processFile(String filename,
Charset charset,
CSVSortedFieldMapProcessor processor)
Processes the CSV file using the provided processor.
|
void |
setComment(char comment)
Sets the comment string value.
|
void |
setDelimiter(char delimiter) |
void |
setHasHeader(boolean hasHeader)
Sets the hasHeader value.
|
public char getComment()
public void setComment(char comment)
comment - the new comment string valuepublic char getDelimiter()
public void setDelimiter(char delimiter)
delimiter - the delimiter to setpublic boolean isHasHeader()
public void setHasHeader(boolean hasHeader)
hasHeader - true if file has a header line; false if notpublic int processFile(String filename, Charset charset, CSVLineProcessor processor) throws IOException, ProcessingException, ParseException
filename - name of CSV fileprocessor - handler to process the CSV linesFileNotFoundException - if file not foundIOException - if a read error occursProcessingException - if an exception is thrown by the processorParseException - if a error occurs parsing the CSV linepublic int processFile(String filename, Charset charset, CSVFieldMapProcessor processor) throws IOException, ProcessingException, ParseException
filename - name of CSV fileprocessor - handler to process the CSV linesFileNotFoundException - if file not foundIOException - if a read error occursProcessingException - if an exception is thrown by the processorParseException - if a error occurs parsing the CSV linepublic int processFile(String filename, Charset charset, CSVSortedFieldMapProcessor processor) throws IOException, ProcessingException, ParseException
filename - name of CSV fileprocessor - handler to process the CSV linesFileNotFoundException - if file not foundIOException - if a read error occursProcessingException - if an exception is thrown by the processorParseException - if a error occurs parsing the CSV lineCopyright © 2020. All Rights Reserved.