Skip to content

Instantly share code, notes, and snippets.

@vamsitallapudi
Created January 16, 2018 07:40
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 vamsitallapudi/3c14d991333577abffbe48c44f7746c4 to your computer and use it in GitHub Desktop.
Save vamsitallapudi/3c14d991333577abffbe48c44f7746c4 to your computer and use it in GitHub Desktop.
Read a file in Kotlin
try {
val inputStream:InputStream = assets.open("news_data_file.json")
val inputStreamReader = InputStreamReader(inputStream)
val sb = StringBuilder()
var line: String?
val br = BufferedReader(inputStreamReader)
line = br.readLine()
while (br.readLine() != null) {
sb.append(line)
line = br.readLine()
}
br.close()
Log.d(TAG,sb.toString())
} catch (e:Exception){
Log.d(TAG, e.toString())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment