KFile

Unified filesystem API offering path utilities, file/directory operations, text and binary I/O, streaming, plus helpers for working directory, user home, temp and current executable.

JVMKotlin/Native
GitHub stars0
Dependents1
Creation date9 months ago

Last activityabout 1 month ago
Latest release0.4.0 (about 1 month ago)

KFile

Maven Central

A Kotlin Multiplatform library providing a unified file-system API for macOS, Linux, Windows, and JVM.

Usage

import es.jvbabi.kfile.File

val cwd = File.getWorkingDirectory()
val home = File.getUserHomeDirectory()
val exe = File.getCurrentExecutableFile()

val file = cwd.resolve("build.gradle.kts")
if (file.exists()) {
    val text = file.readText()
    file.appendText("\n// appended")
}

API

Companion

Method Returns
File(path) Constructs a File, resolving relative paths against the working directory
File.isPathAbsolute(path) Boolean
File.getWorkingDirectory() File
File.getUserHomeDirectory() File
File.getTempDirectory() File
File.getCurrentExecutableFile() File

Properties

Property Type
absolutePath String
name String
extension String
nameWithoutExtension String
parent File?
size Long

Methods

Method Description
exists() Checks if the file or directory exists
isDirectory Checks if the path is a directory
isFile Checks if the path is a regular file
isExecutable Checks if the file is executable
setExecutable(executable) Sets or removes the executable permission
resolve(path) Resolves a child path relative to this file
delete(recursive) Deletes the file or directory
mkdir(recursive) Creates the directory
readText() / writeText(text) / appendText(text) Text I/O
readBytes() / writeBytes(bytes) / appendBytes(bytes) Binary I/O
readLines() / forEachLine(action) Line-by-line reading
source() / sink() / appendSink() Streaming via kotlinx.io
listFiles() Lists children of a directory
copy(to) Copies the file (overwrites destination)

Setup

// settings.gradle.kts
dependencyResolutionManagement {
    repositories { mavenCentral() }
}

// build.gradle.kts
kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("io.github.julius-babies:kfile:VERSION")
        }
    }
}

Replace VERSION with the latest version available on Maven Central.

Platforms

  • macOS (arm64)
  • Linux (x64, arm64)
  • Windows (x64)
  • JVM
JVMKotlin/Native
GitHub stars0
Dependents1
Creation date9 months ago

Last activityabout 1 month ago
Latest release0.4.0 (about 1 month ago)

KFile

Maven Central

A Kotlin Multiplatform library providing a unified file-system API for macOS, Linux, Windows, and JVM.

Usage

import es.jvbabi.kfile.File

val cwd = File.getWorkingDirectory()
val home = File.getUserHomeDirectory()
val exe = File.getCurrentExecutableFile()

val file = cwd.resolve("build.gradle.kts")
if (file.exists()) {
    val text = file.readText()
    file.appendText("\n// appended")
}

API

Companion

Method Returns
File(path) Constructs a File, resolving relative paths against the working directory
File.isPathAbsolute(path) Boolean
File.getWorkingDirectory() File
File.getUserHomeDirectory() File
File.getTempDirectory() File
File.getCurrentExecutableFile() File

Properties

Property Type
absolutePath String
name String
extension String
nameWithoutExtension String
parent File?
size Long

Methods

Method Description
exists() Checks if the file or directory exists
isDirectory Checks if the path is a directory
isFile Checks if the path is a regular file
isExecutable Checks if the file is executable
setExecutable(executable) Sets or removes the executable permission
resolve(path) Resolves a child path relative to this file
delete(recursive) Deletes the file or directory
mkdir(recursive) Creates the directory
readText() / writeText(text) / appendText(text) Text I/O
readBytes() / writeBytes(bytes) / appendBytes(bytes) Binary I/O
readLines() / forEachLine(action) Line-by-line reading
source() / sink() / appendSink() Streaming via kotlinx.io
listFiles() Lists children of a directory
copy(to) Copies the file (overwrites destination)

Setup

// settings.gradle.kts
dependencyResolutionManagement {
    repositories { mavenCentral() }
}

// build.gradle.kts
kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("io.github.julius-babies:kfile:VERSION")
        }
    }
}

Replace VERSION with the latest version available on Maven Central.

Platforms

  • macOS (arm64)
  • Linux (x64, arm64)
  • Windows (x64)
  • JVM