简体   繁体   English

Android filesDir显示为只读

[英]Android filesDir shown as read only

While trying to write a simple file to the applications file directory with phonegap-1.0.0 I get an error with code 5 - NO_MODIFICATION_ALLOWED_ERR . 尝试使用phonegap-1.0.0将简单文件写入应用程序文件目录时,出现代码5- NO_MODIFICATION_ALLOWED_ERR的错误。 The method where I get the directory is like this: 我获取目录的方法是这样的:

function gotFS(fileSystem) {
        fileSystem.root.getFile('file:///data/data/package.name/files/ff.txt', null, gotFileEntry, fail);
    }

As far as I know, the files directory should be writable by the application, and writing to it with a BufferedWriter was successfull. 据我所知,文件目录应该是应用程序可写的,并且使用BufferedWriter写入文件目录是成功的。 I tried only leaving file name, without file:/// and data/data/package.name/. 我尝试仅保留文件名,不包含file:///和data / data / package.name /。 I tried many different versions of Phonegap and many methods only to read/write a file and seems like nothing works. 我尝试了许多不同版本的Phonegap和许多方法来读取/写入文件,但似乎没有任何效果。 Any hint would be appreciated. 任何提示将不胜感激。

The "files directory" should be writeable, but that isn't necessarily it: “文件目录”应该是可写的,但不一定是这样:

  • Android could decide to place application storage under a path other than /data/data/package Android可以决定将应用程序存储放置在/ data / data / package以外的路径下

  • The installed name of the apk can be different, for example it can have a numeric suffix apk的安装名称可以不同,例如,可以带有数字后缀

  • There may not (yet) be a directory called files/ within the application storage 在应用程序存储中可能还没有一个名为files /的目录

You should use the Android API function getFilesDir() or getDir() to get a directory where you are allowed to write from that particular installation on that particular device. 您应该使用Android API函数getFilesDir()getDir()来获取目录,允许您从该特定设备上的特定安装中写入该目录。 Presumably phonegap provides you some means of obtaining the result of one of those functions. 大概phonegap提供了一些获取这些功能之一的结果的方法。

You shouldn't hardcode the path like this. 您不应该这样硬编码路径。 Use getFilesDir() or getDir() functions to get the path instead. 使用getFilesDir()getDir()函数来获取路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM