In this article, we will share program to find directory/application path with an output.
Program: Program to find directory path in Kotlin
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.
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")
}
val fileFullPath = "AskforProgram/Kotlin/Examples/getFileNameExample.kt"
val fileDirectory = fileFullPath.substringBeforeLast("/")
println("dir: $fileDirectory")
}
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.
0 Comments