如何 read/write from/to 与 Kotlin/Native 控制台?

How to read/write from/to console with Kotlin/Native?

我最近尝试使用 Kotlin/Native 将 CLI 工具从 JVM 转换为本机可执行文件。我收到以下错误(这是有道理的):

> Task :compileKotlinMain FAILED
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (4, 8): Unresolved reference: java
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (5, 8): Unresolved reference: java
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (6, 8): Unresolved reference: java
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (9, 14): Unresolved reference: System
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (9, 27): Unresolved reference: System
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (12, 20): Unresolved reference: InputStream
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (12, 38): Unresolved reference: PrintStream
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (16, 57): Unresolved reference: BufferedReader
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (19, 80): Unresolved reference: PrintStream
e: C:\test1\src\main\kotlin\cli\CommandLineTool.kt: (19, 100): Unresolved reference: BufferedReader

Java 支持的控制台 I/O 的替代方案是什么?有图书馆吗? 谢谢。

print 写入其单个参数标准输出。它是重载方法,可以采用 Any? 或任何原始类型。

readLine 从标准输入读取。它没有参数和 returns String?.

这些都来自 kotlin.io 包,这是一个 "IO API for working with files and streams"。