How can I find the path of a file in kotlin?

Viewed 13607

From what I know you can find the path of a file in the internal storage with java simply by using:

String path = context.getFilesDir().getAbsolutePath();    
File file = new File(path + "/filename");

But how do I do this using kotlin?

1 Answers

In Kotlin, when you see a getter method from a Java class, you can omit the get, change the first letter to lower-case, and use it like a Kotlin property:

val path = context.filesDir.absolutePath
val file = File("$path/filename")
Related