KoryFile

class KoryFile(val filePath: String)

A platform-agnostic file wrapper backed by Kotlinx IO.

Provides a unified API for reading, writing, and inspecting files across all Kotlin Multiplatform targets.

Samples

// Getting files from path.
val file = KoryFile.fromPath(filePath) // This function can be thrown a FileNotFoundException!

println(file.mimeTypeStr())

Constructors

Link copied to clipboard
constructor(filePath: String)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The path to the file.

Functions

Link copied to clipboard
fun asKotlinxIOPath(): Path

Returns the underlying Kotlinx IO Path.

Link copied to clipboard
fun delete()
Link copied to clipboard

Checks whether the file exists and is a regular file.

Link copied to clipboard
Link copied to clipboard

Returns the file name (last path segment).

Link copied to clipboard
fun getSink(): Sink
Link copied to clipboard
fun getSize(): Long

Returns the file size in bytes.

Link copied to clipboard

Detects the MIME type of the file.

Link copied to clipboard

Detects the MIME type of the file as a string.

Link copied to clipboard
fun openSource(): Source

Opens a buffered source for reading the file.

Link copied to clipboard

Reads the entire file content as a byte array.

Link copied to clipboard

Writes the given bytes to the file, creating parent directories if needed.