Class CSVParser
java.lang.Object
com.codename1.io.CSVParser
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(InputStream r) Parses input from the given stream and returns the tokens broken into rows and columnsString[][]parse(InputStream r, String encoding) Parses input from the given stream and returns the tokens broken into rows and columnsString[][]Parses input from the given reader and returns the tokens broken into rows and columnsMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()booleanIndicates whether some other object is "equal to" this one.final ClassgetClass()Returns the runtime class of an object.inthashCode()Returns a hash code value for the object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes current thread to wait until another thread invokes the method or the method for this object.final voidwait(long timeout) Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.final voidwait(long timeout, int nanos) Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
-
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:
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:
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:
IOException
-