read file kotlin

import java.io.File

fun main() {
    val fileName = "example.txt"

    // Step 1: Create a File object representing the file to be read
    val file = File(fileName)

    // Step 2: Check if the file exists
    if (file.exists()) {
        // Step 3: Use the readText() extension function to read the entire content of the file
        val content = file.readText()

        // Step 4: Print the content of the file
        println("File Content:")
        println(content)
    } else {
        // Step 5: Handle the case where the file does not exist
        println("File not found: $fileName")
    }
}