admin管理员组文章数量:1335615
I am trying to write a file on my application memory using the following code taken from here:
writeOnFileSystem : function() {
console.log("writeOnFileSystem resolveLocalFileSystemURL ...");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
};
function gotFS(fileSystem) {
fileSystem.root.getFile("file:///data/data/pany.app/readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
...
}
function fail(error) {
console.log(error.code);
}
This throws such exception:
05-14 12:16:55.704: W/System.err(27827): org.apache.cordova.file.EncodingException: This path has an invalid ":" in it.
I am using this string to access my /data/data: file:///data/data/pany.app/readme.txt (pany.app is the package of my app)
- Is this the proper way to access my /data/data?
The same code works if I write on my SD which is done by default on Android.
I am using:
Cordova 3.5.0-0.2.1
org.apache.cordova.file 1.0.1 "File"
org.apache.cordova.file-transfer 0.4.4-dev "File Transfer"
JQM
eclipse
I am trying to write a file on my application memory using the following code taken from here:
writeOnFileSystem : function() {
console.log("writeOnFileSystem resolveLocalFileSystemURL ...");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
};
function gotFS(fileSystem) {
fileSystem.root.getFile("file:///data/data/.pany.app/readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
...
}
function fail(error) {
console.log(error.code);
}
This throws such exception:
05-14 12:16:55.704: W/System.err(27827): org.apache.cordova.file.EncodingException: This path has an invalid ":" in it.
I am using this string to access my /data/data: file:///data/data/.pany.app/readme.txt (.pany.app is the package of my app)
- Is this the proper way to access my /data/data?
The same code works if I write on my SD which is done by default on Android.
I am using:
Cordova 3.5.0-0.2.1
org.apache.cordova.file 1.0.1 "File"
org.apache.cordova.file-transfer 0.4.4-dev "File Transfer"
JQM
eclipse
Share Improve this question asked May 14, 2014 at 10:34 eeadeveeadev 3,85211 gold badges52 silver badges102 bronze badges1 Answer
Reset to default 9Edit: while this answer still holds, there are quite a few changes to the Cordova File API
Anyway,
When you call requestFileSystem
it returns a
FileSystem
object which has a root property which is a DirectoryEntry
.
When you call resolveLocalFileSystemURI
it returns a DirectoryEntry
or
FileEntry
.
So in your case you need to do:
window.resolveLocalFileSystemURI("file:///data/data/{package_name}", onSuccess, onError);
function onSuccess(entry) {
entry.getDirectory("example", {create: true, exclusive: false},onGetDirectorySuccess, onGetDirectoryFail);
}
function onError(error){
console.log(error);
}
the method resolveLocalFileSystemURI
will give you access to the /data/data folder, then you go from there.
The problem with window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
is that on Android it will give you the SD card path if there is an SD card mounted on the device, otherwise it will give you the path to the internal storage (not even sure if data/data/{package_name} or somewhere else). If you ask me, this is one of the most stupid design choices of all times
本文标签: javascriptcordova 3x (phonegap)write on datadata generates encodingExceptionStack Overflow
版权声明:本文标题:javascript - cordova 3.x (phonegap) - write on datadata generates encodingException - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742391994a2466172.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论