Skip to content

Instantly share code, notes, and snippets.

@codenameone
Last active July 8, 2020 09:57
Show Gist options
  • Save codenameone/e60d45dcd79c91be9d31 to your computer and use it in GitHub Desktop.
Save codenameone/e60d45dcd79c91be9d31 to your computer and use it in GitHub Desktop.
Sample usage of the CSVParser class from Codename One designed to parse CSV files
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 < columnNames.length ; iter++) {
columnNames[iter] = "Col " + (iter + 1);
}
TableModel tm = new DefaultTableModel(columnNames, data);
hi.add(BorderLayout.CENTER, new Table(tm));
} catch(IOException err) {
Log.e(err);
}
hi.show();
@codenameone
Copy link
Author

Sample usage of CSVParser.

From the Codename One project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment