Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 654
Jeeva Avatar asked May 25 '26 18:05

Jeeva


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() }
}
like image 159
Jeeva Avatar answered May 27 '26 08:05

Jeeva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!