Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File IO with Kotlin multiplatform

I would like to do some basic filesystem operations on mingwX64 Windows (and possibly other platforms): open, close, read, rename, get metadata, list files in a directory.

I have found one project that promises to implement this functionality: KotlinxIO. However, there has been no progress made in years.

Are there any other alternatives or workarounds?

like image 708
Ford O. Avatar asked Dec 16 '25 23:12

Ford O.


1 Answers

In the end, I used the library Korio. The documentation could be better, but all of the functionality I need is implemented for all platforms (Jvm, Desktop, Android, ..):

import com.soywiz.korio.file.std.*

suspend fun main {
  val cwd = localCurrentDirVfs
  val files = cwd.list()
  cwd["Hello.txt"].open().close()
  cwd["Hello.txt"].renameTo("Hi.txt")
  val metadata = cwd["Hi.txt"].stat()
}

On top of that, it allows usage of the same API for accessing online files, zip archives, etc. which is pretty neat.

like image 65
Ford O. Avatar answered Dec 19 '25 16:12

Ford O.