gpt4 book ai didi

android - 尝试在 Android : open failed: EROFS (Read-only file system) 中创建文件

转载 作者:IT王子 更新时间:2023-10-28 23:40:24 32 4
gpt4 key购买 nike

这一行:

final FileOutputStream outputStream = new FileOutputStream(name);

导致 FileNotFoundException 消息为 /2ozjfFQzwv: open failed: EROFS (Read-only file system) 其中“2ozjfFQzwv”是我传递的名称文件。

我在有和没有 WRITE_INTERNAL_STORAGE 权限的情况下都试过这个。如何创建此文件以进行写入?

或者,我只是希望能够为新 Activity 提供图像,并且它太大而无法在额外中序列化它。有没有比将其写入文件然后再次读取更简单的方法?这里的所有问题似乎都是关于写入 SD 卡的,我不想这样做,因为很多人没有 SD 卡插槽。

最佳答案

I have tried this with and without the WRITE_INTERNAL_STORAGE permission.

Android 中没有 WRITE_INTERNAL_STORAGE 权限。

How do I create this file for writing?

如果您的应用程序以 super 用户权限运行,则您不需要,除非在 root 设备上。您正在尝试写入应用程序无权访问的内部存储的根目录。

请使用带有 File 对象的 FileOutputStream 构造函数版本。根据您可以写入的某个位置创建该 File 对象,例如:

  • getFilesDir()(在您的 Activity 或其他 Context 上调用)
  • getExternalFilesDir()(在您的 Activity 或其他 Context 上调用)

后者需要 WRITE_EXTERNAL_STORAGE 作为权限。

Is there an easier way than writing it to a file then reading from it again?

你可以暂时把它放在一个静态数据成员中。

because many people don't have SD card slots

“SD 卡插槽”基本上是无关紧要的。 99% 的 Android 设备用户将拥有外部存储设备——用户移除 SD 卡的 4 年以上设备除外。自 2010 年中以来生产的设备将外部存储作为板载闪存的一部分,而不是作为可移动媒体。

关于android - 尝试在 Android : open failed: EROFS (Read-only file system) 中创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15711098/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com