Kotlin – Get File Extension

Kotlin – Get File Extension : In Kotlin, to extract or get the file extension, use File.extension property. File.extension is a String value. It returns the extension if the file has one or an empty string if the file does not have an extension.

Example – Get File Extension in Kotlin

In the following example we shall walk through all the files in the project root directory (if you are running the program from IDE) or all the files in the directory from which you are running the Kotlin program in command line, and print the extension of each file.