Program to find file extension in kotlin

In this article, we will share the program to find file extension with an output.

Program:
fun main(args: Array<String>) {
    val fileFullPath = "AskforProgram/Kotlin/Examples/getFileNameExample.kt"
    val fileExtension = fileFullPath.substringAfterLast(".")

    println("File Extention: $fileExtension")
}

Output:
Kotlin program to find file extension with output
Kotlin program to find file extension with an output

Program Description:
1 fileFullPath variable contains a sample path of the directory.

2 .substringAfterLast() - function will find the last index of "." character, and then it will return the string from that index to end of a string.

3 println() function will print file extention.

Post a Comment

0 Comments