Bundle Files with Compose for Desktop

Viewed 110

I am an Android developer, 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.

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.

Edit

Not only JSON files, but I also want to store some other files like HTML, so I really need a way to store files within the application.

1 Answers

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() }
}
Related