Last active
July 8, 2020 09:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of CSVParser.
From the Codename One project