create

fun create(path: String, rewriteExists: Boolean = false, block: (KoryFile) -> Unit? = null): KoryFile

Creates a new file at the given path and runs the given block on it.

Return

The created KoryFile.

Parameters

path

The path to the file.

rewriteExists

If true, overwrites an existing file. Defaults to false.

block

Callback invoked with the created KoryFile.

Throws

if the file exists and rewriteExists is false.

Samples

KoryFile.create("file.ext") { file ->
    // Use file functions.
    // Example: file.writeBytes(ByteArray(4096))
}