Skip to content

ykws/kotlin-csv-example

Repository files navigation

Example use kotlin-csv

What exception is thrown when try to read a csv file with kotlin-csv?

for example

throws MalformedCSVException when header 'name' is duplicated.

        try {
            csvReader().open(assets.open("invalid.csv")) {
                // throws MalformedCSVException
                readAllWithHeaderAsSequence().forEach { row: Map<String, String> ->
                    Log.d("CSV", row.getValue("name"))
                }
            }
        } catch(e: Exception) {
            e.printStackTrace()
        }

throws NoSuchElementException when Key ame is missing in the map.

        try {
            csvReader().open(assets.open("valid.csv")) {
                readAllWithHeaderAsSequence().forEach { row: Map<String, String> ->
                    // throws NoSuchElementException
                    Log.d("CSV", row.getValue("ame"))
                }
            }
        } catch(e: Exception) {
            e.printStackTrace()
        }