public class CSVReader extends AbstractDataReader
Class that creates a DataSource
from file contents which are
separated by a certain delimiter character. The delimiter is chosen based on
the file type but can also be set manually. By default the comma character
will be used as a delimiter for separating columns.
CSVReader
instances should be obtained by the
DataReaderFactory
rather than being created manually:
DataReaderFactory factory = DataReaderFactory.getInstance(); DataReader reader = factory.get("text/csv"); reader.read(new FileInputStream(filename), Integer.class, Double.class);
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SEPARATOR_CHAR
Key for specifying a
Character value that defines the
delimiting character used to separate columns. |
Constructor and Description |
---|
CSVReader(java.lang.String mimeType)
Creates a new instance with the specified MIME type.
|
Modifier and Type | Method and Description |
---|---|
DataSource |
read(java.io.InputStream input,
java.lang.Class<? extends java.lang.Comparable<?>>... types)
Returns a DataSource that was imported.
|
getMimeType, getSetting, setDefault, setSetting
addCapabilities, getCapabilities
public static final java.lang.String SEPARATOR_CHAR
Character
value that defines the
delimiting character used to separate columns.public CSVReader(java.lang.String mimeType)
mimeType
- MIME type of the file format to be read.public DataSource read(java.io.InputStream input, java.lang.Class<? extends java.lang.Comparable<?>>... types) throws java.io.IOException
input
- Input to be read.types
- Number types for the columns of the DataSource.java.io.IOException
- when the file format is not valid or when
experiencing an error during file operations.