Looking for a library or an alternative for basic multiplatform File I/O

Hi all,

I posted this question recently on the r/Kotlin subreddit (here). Afterwards I thought that I might get better answers here, since I really enjoy this community. I’d be glad if you could help me!

I’m trying to find the best way to interact with a filesystem and do basic operations on it (I/O). My requirements would be:

  • multiplatform
  • (compatible with) Kotlin v1.4.32
  • FS navigation ( Path )
  • Basic I/O (most importantly txt file reading, maybe also writing, creating/deleting)
  • Bonus Points if it can be done nonblockingly

What would not be needed:

  • streaming possibilities
  • random access
  • control over platform-specific details
  • basically anything that is more advanced than basic CRUD

I don’t think it’s a good idea to wait for kotlinx.io *, so what could other alternatives be? The last option would be to implement it with expect / actual for every platform, but maybe there’s already a fitting library for this? Maybe korio? Does anyone have experience with it, is it up-to-date and well usable?

Thanks for your input!

* I get it that they don’t want to waste their resources on something that is low-priority, but I really don’t understand why such an essential thing as multiplatform I/O is considered “low priority”. Sad story.

It seems obvious how the file I/O would be done in Java and Native.

But what about JavaScript? Kotlin/JS runs in a browser usually? How would you suggest to map normal filesystem I/O API into browser environment?

I suspect OP doesn’t need an advanced filesystem API, only basic operations.

Something simple that has JVM actuals using java.nio and maybe a basic virtual filesystem on JS?

1 Like

First of all, thanks for the replies. Indeed, as @arocnies pointed out, I would not need anything “advanced” when it comes to the filesystem API. Basically, my goal with trying to go multiplatform is to be a maximally inclusive library. So when @skylen asks how it should work in a browser env, I have to admit that I have no idea. And that is because I do not intend to use it with Kotlin/JS, but I want to provide this possibilty for others. Considering this, a VFS interface for browser environments would probably be the best choice, so that library users can decide on their own how FS interaction in a browser should look like.

Apart from that the minimal requirements for me would really just be:

  • read text from file
  • adress file by path
  • some path composition utilities
  • NIO

If anyone can recommend a library for that, I’d be thankful. korio seems promising, and I also got okio recommended. Does anyone know these libs and can tell me whether they are proper and also fitting my use case?


Not sure why koperagen delete his reply but Korio might be worth looking at–although it provides a bit more than just a virtual filesystem.


MokoResources is probably something worth to have a look. We’re using at work, it does what it supposed to do but it’s not that easy to integrate

Thank you for your reply!

I’m sure moko-resources is great, but I actually don’t want to target mobile primarily (although it might be yet another supported platform for my multiplatform project). My most important target is JVM, although I also want to support native and (if possible, see earlier discussion) JS.

1 Like

Hey is it possible to set MK string from layout xml? only way to set string is through code is it?