https://kotlinlang.org logo
#getting-started
Title
# getting-started
n

nilTheDev

08/20/2021, 5:26 AM
Can't import
kotlin.io.path
. Tried invalidating caches and restart. Still no luck. Any idea on how to make this work?
k

Klitos Kyriacou

08/20/2021, 8:12 AM
What is it you actually want to do? Path is in java.io.file.Path. Kotlin adds extension functions to the Path class. These extension functions are declared in kotlin.io but are implicitly imported so you don't have to.
n

nilTheDev

08/20/2021, 8:20 AM
I just want to use this
Path
constructor, from Kotlin's standard library, instead of Java's
Paths.get()
method. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io.path/
k

Klitos Kyriacou

08/20/2021, 8:29 AM
This was introduced in Kotlin 1.5. Are you using an IDE plugin for the latest version?
i

ilya.gorbunov

08/20/2021, 3:34 PM
You need to depend on
kotlin-stdlib-jdk7
or
-jdk8
to use
kotlin.io.path
package. Usually stdlib dependencies are added automatically by Kotlin gradle plugin, but sometimes gradle plugin fails to determine that it's ok to use
kotlin-stdlib-jdk8
and adds a dependency on
kotlin-stdlib
only.
n

nilTheDev

08/21/2021, 3:26 PM
@Klitos Kyriacou Yes, I am using the latest version.
@ilya.gorbunov Adding
kotlin-stdlib-jdk7
does the job. Thank You so much. But it is really confusing for a beginner to understand why something from the
stdlib
works and why it doesn't.
143 Views