How to get the current working directory in Kotlin?

Viewed 7296

I need to know the full path of my current working directory of my simple application using Kotlin.

3 Answers

This will provide the full absolute path from where application will run.

import java.nio.file.Paths

val path = Paths.get("").toAbsolutePath().toString()       

You can also get it from System.

val path = System.getProperty("user.dir")

If you are working with kotlin on android try with:

Kotlin

applicationInfo.dataDir

if you are working on android using Java.

getApplicationInfo().dataDir

it returns a String.

Related