I/OFor more control over file operations:

I/O

File I/O

High-Level Functions

import io.file
FunctionSignatureDescription
readText(path: String) r: StringRead entire file to string
writeText(path: String, content: String) r: BoolWrite string to file
appendText(path: String, content: String) r: BoolAppend string to file
exists(path: String) r: BoolCheck if file exists
deleteFile(path: String) r: BoolDelete a file
createDirectory(path: String) r: BoolCreate a directory
ensureParentDirectories(path: String) r: BoolCreate parent directories needed for a file path
writeLines(path: String, lines: Array<String>) r: BoolWrite lines with newline separators
size(path: String) r: IntReturn file size, or -1 on failure
hash(path: String) r: StringReturn a stable file-content hash string

Example

let content = readText("config.toml")
println("Config: {content}")

writeText("output.txt", "Hello, World!")

FsFile Class

For more control over file operations:

let file = FsFile.open("data.txt")
let content = file.readContent()
file.closeFile()
MethodReturnDescription
open(path: String)FsFileOpen for reading
create(path: String)FsFileOpen for writing (create/truncate)
readContent()StringRead all content
read_bytes(size: Int)Array<Int>Read N bytes
writeContent(content: String)VoidWrite string
write_bytes(data: Array<Int>)VoidWrite bytes
closeFile()VoidClose file
size()IntGet file size

FsFileResult represents file-open/read outcomes that need to carry success state alongside file data or errors.

Runtime File Functions

FunctionDescription
__OpenFile(path, mode)Open file, return fd (-1 on error)
__ReadFile(fd)Read entire content
__ReadFileBytes(fd, size)Read N bytes
__WriteFile(fd, content)Write string
__WriteFileBytes(fd, bytes)Write byte array
__CloseFile(fd)Close file descriptor
__FileSize(fd)Get file size
__FileError(fd)Get error message
__FileExists(path)Check existence
__DeleteFile(path)Delete file
__CreateDirectory(path)Create directory

Standard I/O

Output

FunctionDescription
println(s: String)Print string with newline
__Print(s: String)Print without newline
__PrintInt(n: Int)Print integer
__PrintFloat(f: Float)Print float
__PrintRaw(s: String)Print without newline (for LSP headers)
__FlushStdout()Flush stdout buffer

Input

FunctionDescription
__ReadStdinLine()Read one line from stdin (blocking)
__ReadStdinBytes(count: Int)Read exactly N bytes from stdin

StdinReader Class

import io.stdio
MethodReturnDescription
nextLine()StringRead next line
isEof()BoolCheck end of input

ContentLengthReader

For LSP/JSON-RPC message framing:

let reader = ContentLengthReader.new()
let message = reader.readMessage()
let err = reader.getLastError()

Buffered I/O

import io.buffered
  • BufferedWriter -- buffered output
  • BufferedReader -- buffered input

Path Operations

import fs.path
FunctionSignatureDescription
isAbsolute(path: String) r: BoolCheck absolute path
normalize(path: String) r: StringNormalize path
join(parts: Array<String>) r: StringJoin path components
basename(path: String) r: StringGet filename
dirname(path: String) r: StringGet directory
pathExtension(path: String) r: StringGet file extension
withoutExtension(path: String) r: StringRemove extension
splitComponents(path: String) r: Array<String>Split into components

Example

let full = join(["home", "user", "docs", "file.txt"])
let dir = dirname(full)       // "home/user/docs"
let file = basename(full)     // "file.txt"
let ext = pathExtension(full) // "txt"
Architected in Kotlin. Rendered with Materia. Powered by Aether.
© 2026 Yousef.