开发者

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. 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 a开发者_JS百科pplication, and writing to it with a BufferedWriter was successfull. I tried only leaving file name, without file:/// and 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. 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

  • The installed name of the apk can be different, for example it can have a numeric suffix

  • There may not (yet) be a directory called files/ within the application storage

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. Presumably phonegap provides you some means of obtaining the result of one of those functions.


You shouldn't hardcode the path like this. Use getFilesDir() or getDir() functions to get the path instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜