试图在Android中创建一个文件:打开失败:EROFS(只读文件系统) [英] Trying to create a file in Android: open failed: EROFS (Read-only file system)

查看:3810
本文介绍了试图在Android中创建一个文件:打开失败:EROFS(只读文件系统)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这行:

 最后的FileOutputStream的OutputStream =新的FileOutputStream(名称);
 

导致 FileNotFoundException异常的消息是 / 2ozjfFQzwv:打开失败:EROFS(只读文件系统)其中2ozjfFQzwv是我传递的​​文件的名称。

我已经试过这种使用和不使用 WRITE_INTERNAL_STORAG​​E 许可。如何创建这个文件写?

另外,我只是希望能够给一个图像到一个新的活动,这是太大,它在一个额外的序列化。有没有比它写入到文件,然后从它再次阅读更简单的方法?所有在这里的问题似乎是有关编写到SD卡,这是我不想这样做,因为很多人没有SD卡插槽。

解决方案
  

我曾试图与和没有WRITE_INTERNAL_STORAG​​E许可。

目前在Android中没有 WRITE_INTERNAL_STORAG​​E 许可。

  

如何创建这个文件写?

您不这样做,也许除了一个根深蒂固的设备,如果你的应用程序与超级用户privilges运行。您正在尝试编写的内部存储的根源,哪些应用程序不能访问到。

请使用的FileOutputStream 构造,需要一个文件对象的版本。根据创建了一些位置,即文件的对象,你可以写,如:

  • getFilesDir()(叫上你的活动或其他上下文
  • getExternalFilesDir()(叫上你的活动或其他上下文

后者需要 WRITE_EXTERNAL_STORAG​​E 的权限。

  

有没有比它写入到文件,然后从中读取一次更简单的方法?

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

  

因为很多人没有SD卡插槽

SD卡插槽是不相关的,由大。 99%的Andr​​oid设备的用户将有外部存储 - 除了会在用户删除他们的SD卡4+岁装置。 2010年中期以来制造的设备有外部存储的板载闪存,而不是作为可移动媒体的一部分。

This line:

final FileOutputStream outputStream = new FileOutputStream(name);

results in a FileNotFoundException with the message being /2ozjfFQzwv: open failed: EROFS (Read-only file system) where "2ozjfFQzwv" is what I passed as the name of the file.

I have tried this with and without the WRITE_INTERNAL_STORAGE permission. How do I create this file for writing?

Alternatively, I just want to be able to give an image to a new activity, and it is too large to serialize it in an extra. Is there an easier way than writing it to a file then reading from it again? All the questions on here seem to be about writing to an SD card, which I don't want to do because many people don't have SD card slots.

解决方案

I have tried this with and without the WRITE_INTERNAL_STORAGE permission.

There is no WRITE_INTERNAL_STORAGE permission in Android.

How do I create this file for writing?

You don't, except perhaps on a rooted device, if your app is running with superuser privilges. You are trying to write to the root of internal storage, which apps do not have access to.

Please use the version of the FileOutputStream constructor that takes a File object. Create that File object based off of some location that you can write to, such as:

  • getFilesDir() (called on your Activity or other Context)
  • getExternalFilesDir() (called on your Activity or other Context)

The latter will require WRITE_EXTERNAL_STORAGE as a permission.

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

You can temporarily put it in a static data member.

because many people don't have SD card slots

"SD card slots" are irrelevant, by and large. 99% of Android device users will have external storage -- the exception will be 4+ year old devices where the user removed their SD card. Devices manufactured since mid-2010 have external storage as part of on-board flash, not as removable media.

这篇关于试图在Android中创建一个文件:打开失败:EROFS(只读文件系统)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆