I am trying to read a text file that is already saved in my directory and print it on the screen as a TextView. This is the code that I have so far. However, when I run the
This is the Kotlin version of the answer from above:
var text = ""
var reader: BufferedReader? = null
try {
reader = BufferedReader(InputStreamReader(assets.open("inputNews.txt")))
text = reader.readLines().joinToString("\n")
} catch (e: IOException) {
Toast.makeText(applicationContext, "Error reading license file!", Toast.LENGTH_SHORT).show()
e.printStackTrace()
} finally {
try {
reader?.close()
} catch (e: IOException) {
//log the exception
e.printStackTrace()
}
textView.text = text
}