Class CSVParser
java.lang.Object
com.codename1.io.CSVParser
public class CSVParser
extends java.lang.Object
The CSVParser allows importing data into applications quickly from a CSV source. CSV
is a file format
that is supported by all spreadsheets and most databases for data exchange.
The sample below lists a simple hardcoded CSV within the table:
Form hi = new Form("CSV Parsing", new BorderLayout());
CSVParser parser = new CSVParser();
try(Reader r = new com.codename1.io.CharArrayReader("1997,Ford,E350,\"Super, \"\"luxurious\"\" truck\"".toCharArray())) {
String[][] data = parser.parse(r);
String[] columnNames = new String[data[0].length];
for(int iter= 0 ; iter
@author Shai Almog
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionString[][]parse(java.io.InputStream r) Parses input from the given stream and returns the tokens broken into rows and columnsString[][]Parses input from the given stream and returns the tokens broken into rows and columnsString[][]parse(java.io.Reader r) Parses input from the given reader and returns the tokens broken into rows and columnsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
CSVParser
public CSVParser()Initializes a parser with the default comma (',') separator char -
CSVParser
public CSVParser(char separatorChar) Allows creating a parser with a custom separator char
Parameters
separatorChar: custom separator character such as semi-colon (';') etc.
-
-
Method Details
-
parse
Parses input from the given stream and returns the tokens broken into rows and columns
Parameters
r: the input stream
Returns
array of rows and columns
- Throws:
java.io.IOException
-
parse
Parses input from the given stream and returns the tokens broken into rows and columns
Parameters
-
r: the input stream -
encoding: the encoding of the stream
Returns
array of rows and columns
- Throws:
java.io.IOException
-
-
parse
Parses input from the given reader and returns the tokens broken into rows and columns
Parameters
r: the reader stream
Returns
array of rows and columns
- Throws:
java.io.IOException
-