Search code examples
kotlinandroid-jetpack-composecompose-desktopcompose-multiplatform

Bundle files with Compose for Desktop (Compose Multiplatform)


I am an Android developer and I have experience with Jetpack Compose. Now, I am trying to build desktop apps, so I found this Compose for Desktop project. I want to store a JSON file with my desktop app so that I can read the file from my desktop app and show it to users. Not only JSON files, but I also want to store some other files like HTML.

In Android, I could use the raw or assets folders, but I don't know how to do that in Compose for Desktop.

If someone can point me in the right direction, I will appreciate it.


Solution

  • You can put any assets files inside src\jvmMain\resources access them using useResource.

    for example to read json file as text:

    useResource("data.json") { stream ->
        val textJson = stream.bufferedReader().use { it.readText() }
    }