Created
October 9, 2017 11:59
-
-
Save Audhil/d1f8b5997aa196b4d987a6b012054b94 to your computer and use it in GitHub Desktop.
File reading in Kotlin, FYI
This file contains 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
// Java code | |
BufferedReader br = null; | |
br = new BufferedReader(new InputStreamReader(assetManager.open(actualFilename))); | |
String line; | |
ArrayList<String> labels = new ArrayList<String>(); | |
while ((line = br.readLine()) != null) { | |
labels.add(line); | |
} | |
br.close(); | |
// Kotlin code | |
val labels = ArrayList<String>() | |
val inputStream = am.open(fileName) | |
inputStream.bufferedReader().useLines { | |
lines -> | |
lines.forEach { | |
labels.add(it) | |
} | |
} | |
refer for more info : http://kotlination.com/kotlin/read-file-kotlin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment