androidkotlin

Android Kotlin assert list is empty but file is in folder


I am trying to read a file in via Android assets folder. For this I made a assets folder like here. I made a file and it is shows in the explore:

enter image description here

When I run in the onCreate method: Log.d("Test", assets.list("/").contentToString()) The output is [].

Also when I run:

assets.open("Injector.js").bufferedReader().use {
    Log.d("Test", it.readText())
}

The output is "" or Nothing.

Is there anybody familiar with this issue or has any ideas how to resolve this? If you need more information please let me know.

Thanks in advance


Solution

  • try with applicationContext like this:

    applicationContext.assets.open("Injector.js").bufferedReader().use {
         Log.d("Test", it.readText())
    }