【问题标题】:How to properly create a .txt file within the Android project directory (and be able to edit it)?如何在 Android 项目目录中正确创建 .txt 文件(并能够对其进行编辑)?
【发布时间】:2016-11-30 06:47:33
【问题描述】:

我是 Android 新手。我搜索了如何在 Android 目录中创建一个文件,并导致这篇文章提到将其保存到资产目录:Where to put text files in directory in Android

我的问题是,我无法编辑资产目录中的文件。

context.openFileOutput 将其保存到context.getFilesDir() 返回的内容中,即/data/ 文件夹(据我了解,该文件夹不在项目目录中,因为我需要请求权限)但是我在保存时遇到的问题即使我有保存权限,我的权限也被拒绝(我发了一篇关于它的帖子:Getting a Permission denied error when creating a file with Android, even when permission is given

话虽如此,将 .txt 文件保存在 Android 项目目录中而不是资产文件夹中的正确方法是什么?

【问题讨论】:

  • .txt文件的内容是什么?
  • 你能告诉我们你的代码吗?

标签: android android-permissions


【解决方案1】:

你不能那样做。 “项目目录”(基本上是安装在设备上的 APK 的内容)是只读的。 Android 为您提供了许多可以写入数据的地方:

  • 特定于应用程序的私有数据目录
  • 共享偏好
  • 外部存储(SD 卡或类似设备)
  • SQLite 数据库

【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多