public class CsvReader extends LineNumberReader
CsvReader
instance is used read text files with CSV (comma separated values) format.
This reader interprets each line of a text file as record (also empty lines). The fields of the record are delimited by a single separator character which must not necessarily be a comma.
Constructor and Description |
---|
CsvReader(Reader reader,
char[] separators)
Constructs a CSV reader using the given column separator characters.
|
CsvReader(Reader reader,
char[] separators,
boolean ignoreEmptyLines,
String commentPrefix)
Constructs a CSV reader using the given column separator characters and the format properties.
|
Modifier and Type | Method and Description |
---|---|
String |
getCommentPrefix()
Gets the comment prefix string (if any).
|
char[] |
getSeparators() |
boolean |
ignoresEmptyLines() |
double[] |
readDoubleRecord() |
List<double[]> |
readDoubleRecords() |
String[] |
readRecord()
Reads a record info from the database.
|
List<String[]> |
readStringRecords()
Reads the complete file from the current position on.
|
getLineNumber, mark, read, read, readLine, reset, setLineNumber, skip
close, lines, markSupported, ready
public CsvReader(Reader reader, char[] separators)
reader
- the underlying reader to be wrappedseparators
- the column separator characterspublic CsvReader(Reader reader, char[] separators, boolean ignoreEmptyLines, String commentPrefix)
reader
- the underlying reader to be wrappedseparators
- the column separator charactersignoreEmptyLines
- if true
, empty lines are ignoredcommentPrefix
- if not null
, the prefix string for comment linespublic final char[] getSeparators()
public final boolean ignoresEmptyLines()
public final String getCommentPrefix()
null
otherwise.public String[] readRecord() throws IOException
Leading and trailing whitespaces removed from each column value. For empty lines, the method returns an
array of the length zero. The method returns null
if the end of file has been reached.
IOException
- if an I/O error occurspublic double[] readDoubleRecord() throws IOException
IOException
public List<String[]> readStringRecords() throws IOException
readLineRecord
has not previously been
called the method reads all records from the beginning of the file. For empty files, the method returns an vector
having a zero size.String[]
records containing the tokens delimitted by the separator character
passed to the constructorIOException
- if an I/O error occurspublic List<double[]> readDoubleRecords() throws IOException
IOException
Copyright © 2014–2015 European Space Agency (ESA). All rights reserved.