In this article, we will share the program to find file extension with an output.
Program:
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.
Program:
fun main(args: Array<String>) {
val fileFullPath = "AskforProgram/Kotlin/Examples/getFileNameExample.kt"
val fileExtension = fileFullPath.substringAfterLast(".")
println("File Extention: $fileExtension")
}
val fileFullPath = "AskforProgram/Kotlin/Examples/getFileNameExample.kt"
val fileExtension = fileFullPath.substringAfterLast(".")
println("File Extention: $fileExtension")
}
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.
0 Comments