Class CSVParser

java.lang.Object
com.codename1.io.CSVParser

public class CSVParser extends 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
    Constructor
    Description
    Initializes a parser with the default comma (',') separator char
    CSVParser(char separatorChar)
    Allows creating a parser with a custom separator char
  • Method Summary

    Modifier and Type
    Method
    Description
    String[][]
    Parses input from the given stream and returns the tokens broken into rows and columns
    String[][]
    parse(InputStream r, String encoding)
    Parses input from the given stream and returns the tokens broken into rows and columns
    String[][]
    Parses input from the given reader and returns the tokens broken into rows and columns

    Methods inherited from class 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

      public String[][] parse(InputStream r) throws IOException

      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

      public String[][] parse(InputStream r, String encoding) throws IOException

      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

      public String[][] parse(Reader r) throws IOException

      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