Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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) {

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


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.



This post first appeared on Ask For Program, please read the originial post: here

Share the post

Kotlin program to find directory/application path

×

Subscribe to Ask For Program

Get updates delivered right to your inbox!

Thank you for your subscription

×