[英]Importing java classes in Intellij Kotlin app
I am using IntelliJ for the first time to write a Kotlin program for windows.我第一次使用 IntelliJ 为 windows 编写 Kotlin 程序。
I need to read a file so I used code from a sample site:我需要读取一个文件,所以我使用了示例站点中的代码:
import java.io.File
import java.io.InputStream
fun main(args: Array<String>) {
val inputStream: InputStream = File("bezkoder.txt").inputStream()
val lineList = mutableListOf<String>()
inputStream.bufferedReader().useLines { lines -> lines.forEach { lineList.add(it)} }
lineList.forEach{println("> " + it)}
}
The thing is that it doesn't recognise the import for the java classes.问题是它无法识别 java 类的导入。
I guess it is something in my setup but I have no idea where to look and haven't managed to find an answer.我想这是我的设置中的一些东西,但我不知道在哪里看,也没有设法找到答案。
This is my SDK setup screen这是我的 SDK 设置屏幕
You can't use Java SDK classes in the Kotlin/Native projects, only in Kotlin/JVM.您不能在 Kotlin/Native 项目中使用 Java SDK 类,只能在 Kotlin/JVM 中使用。
Please also make sure you have a valid JDK configuration in the project.还请确保您在项目中具有有效的 JDK 配置。 See this answer for more details.
有关更多详细信息,请参阅此答案。
If you want to read a file in Kotlin Native, see CsvParser.kt example.如果要读取 Kotlin Native 中的文件,请参阅CsvParser.kt示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.