Handling files in multi-platform projects?


#1

Is there any support for file handing in multi-platform projects? Something similar to java.io.File. I didn’t find anything in the standard library. https://github.com/Kotlin/kotlinx-io looked promising, but does not have a File class.


#2

No, not in the way that you would like. And I think such an API will never be introduced, because it would be a huge commitment. The differences between the capabilities of the platforms that Kotlin compiles too are very big.

Kotlin itself is not a platform like Java is, i.e. it is not intended to provide an abstraction for files, GUIs, etc. that works the same on multiple platforms. Kotlin provides a language and a (limited) standard library that is relatively easy to support on all platforms supported by Kotlin.

The goal of multi-platform projects is to share common business logic, but using files, creating GUIs, interacting with sensors, etc. have to be done in a platform-specific way. This way you will not be limited by an (simple) abstraction in Kotlin, but you can use the full power of what each platform provides. The downside is that you have to write code for doing the same thing for multiple platforms.