【问题标题】:How to convert ByteArray to String with specified charset in Kotlin如何在 Kotlin 中将 ByteArray 转换为具有指定字符集的字符串
【发布时间】:2017-06-14 08:47:49
【问题描述】:

我发现 Kotlin 中有一个 ByteArray.toString(charset:Charset) 函数,当我在 android studio IDE 中使用该函数时,它会出现语法错误。但我在 Kotlin org 网站上尝试过相同的代码,效果很好。如何在 Kotlin 中将 ByteArray 转换为 String?

【问题讨论】:

  • 仅使用您的代码我没有收到该错误。
  • 试试这个构造函数:String(bytes, charset)。还要检查您的项目中是否包含 Kotlin 标准库。
  • 你可以试试 val str = String(bytes)

标签: android android-studio kotlin


【解决方案1】:

您似乎没有为 Kotlin 配置项目(您的类路径中没有 kotlin-runtime.jar)。尝试选择有错误的行,按Alt+Enter 并在上下文菜单中选择“Kotlin 未配置”->“配置” 或者手动将 kotlin-runtime.jar 添加到你的类路径

【讨论】:

    猜你喜欢
    • 2021-06-11
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 2016-06-04
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    相关资源
    最近更新 更多