writer

Returns a new OutputStreamWriter for writing the content of this file.

inline fun Path.writer(charset: Charset = Charsets.UTF_8, vararg options: OpenOption): OutputStreamWriter(source)
import java.nio.file.*
import java.nio.charset.*

fun main() {
    val path = Paths.get("example.txt")
    path.writer(Charsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
        .use { writer ->
            writer.write("Hello, Kotlin writer!")
        }
}

Source