Read the text object (text file from the data folder) as a string in Kotlin (Android)

I need to read a text file stored in src/main/assets/ie; in the resource folder and get it as a string.

Is there an easy way to do this.

Java copying, pasting, function conversion give problems, so I would prefer to use the kotlin method.

I need a kotlin way to do this

+4
source share
1 answer

I found this in a video on YouTube. Here is the link https://www.youtube.com/watch?v=o5pDghyRHmI

val file_name = "qjsonfile.json"
val json_string = application.assets.open(file_name).bufferedReader().use{
            it.readText()
        }

Saves JSON or text in a string json_string.

+13
source

Source: https://habr.com/ru/post/1689003/


All Articles