Kotlin write a file with writeText

The writeText() is a Kotlin File extension function which writes text encoded using UTF-8 or other charsets to the file. If this file exists, it becomes overwritten.

Kotlin write a file with writeText

The example writes to a file with Kotlin writeText() extension function.
import java.io.File

fun main(args: Array<String>) {

    val fileName = "src/resources/myfile3.txt"
    val myfile = File(fileName)

    val content = "Today snow is falling."


    println("Writed to file")

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course