Kotlin program to find directory/application path

In this article, we will share program to find directory/application path with an output.

Program: Program to find directory path in Kotlin
fun main(args: Array<String>) {

val fileFullPath = "AskforProgram/Kotlin/Examples/getFileNameExample.kt"
val fileDirectory = fileFullPath.substringBeforeLast("/")

println("dir: $fileDirectory")
}

Output:

Kotlin program to find application directory path using substringBeforeLast() - Output
Kotlin program to find application directory path using substringBeforeLast() - Output


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

2 .substringBeforeLast() - function will find last index of "/" character, and then it will return string till that index from first.

3 println() function prints directory path.

Post a Comment

0 Comments