Skip to content

Instantly share code, notes, and snippets.

@stella6767
Last active July 27, 2022 03:26
Show Gist options
  • Save stella6767/922a6fe7c3cb5313a3cbb1cbbd4fb1be to your computer and use it in GitHub Desktop.
Save stella6767/922a6fe7c3cb5313a3cbb1cbbd4fb1be to your computer and use it in GitHub Desktop.
readDataFromCsv
fun readDataFromCsv(filePath: String): List<List<String>?> {
var csvList: MutableList<List<String>?> = mutableListOf()
val csv = java.io.File(filePath)
try {
BufferedReader(FileReader(csv)).use { br ->
var line: String?
while (br.readLine().also { line = it } != null) {
//println("line $line")
val split: List<String>? = line?.split(",")
csvList.add(split)
}
}
} catch (e: IOException) {
e.printStackTrace()
}
return csvList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment