【问题标题】:How to save a ByteArray in the internal storage in Kotlin Android?如何在 Kotlin Android 的内部存储中保存 ByteArray?
【发布时间】:2021-06-12 03:57:02
【问题描述】:

我正在尝试在 Kotlin 的 Android 内部存储中保存一个包含 ByteArray 的文件,但我找到的每个示例总是告诉我要使用它:

val file = File(context.filesDir, name)

但是context 没有定义,并且知道它应该是什么。 var 上下文的假定定义是什么?

谢谢!

【问题讨论】:

标签: android arrays android-studio file kotlin


【解决方案1】:

用 this.getApplicationContext() 替换上下文

val file = File(this.getApplicationContext().filesDir, name)

【讨论】:

  • 谢谢!这解决了我的问题。另外,this.applicationContext 是否与this.getApplicationContext() 相同
  • 是的,Kotlin 不那么冗长
  • 完美,太棒了!感谢您花时间解决我的疑问。 ^^
猜你喜欢
  • 2019-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多