【问题标题】:How can I find the path of a file in kotlin?如何在 kotlin 中找到文件的路径?
【发布时间】:2019-10-18 16:49:31
【问题描述】:

据我所知,您只需使用 java 即可在内部存储中找到文件的路径:

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

但是我如何使用 kotlin 做到这一点?

【问题讨论】:

    标签: android-studio kotlin


    【解决方案1】:

    在 Kotlin 中,当您看到来自 Java 类的 getter 方法时,您可以省略 get,将第一个字母更改为小写,并将其用作 Kotlin 属性:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多