Skip to content

Instantly share code, notes, and snippets.

@Audhil
Created October 9, 2017 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Audhil/d1f8b5997aa196b4d987a6b012054b94 to your computer and use it in GitHub Desktop.
Save Audhil/d1f8b5997aa196b4d987a6b012054b94 to your computer and use it in GitHub Desktop.
File reading in Kotlin, FYI
// 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