根据cordova-plugin-file api,https://www.npmjs.com/package/cordova-plugin-file,cordova.file.application目录是readOnly,这是有道理的。然而,没有意义的是,在引用应用程序目录内的文件的FileEntry对象上初始化文件编写器不会引发错误。谢天谢地,它似乎也没有写入文件,但仍然应该抛出错误的错误?
这是一个错误还是我误解了api的工作方式?
function write(json, callBack){
var retVal = "";
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory+"www/fooFiles/foo.txt", function(fileEntry){
console.log(fileEntry);
fileEntry.file(function(file){
console.log("got file");
console.log(file);
/*an error should be thrown here*/
fileEntry.createWriter(function(fileWriter) {
//fileWriter.seek(fileWriter.length);
var blob = new Blob(["testing this used to be json"], {type:'text/plain'});
fileWriter.write(blob);
console.log("success");
retVal=true;
callBack(retVal);
}, function(){
console.log("File write failed");
retVal=false;
callBack(retVal);
});
}, function(error){
console.log("Error getting file");
console.log(error);
});
});
}