我一直在尝试使用 phonegap/cordova API 中的示例,让应用程序将一些文本写入 windows phone 的 phonegap/cordova 1.6.0 下的文件,但没有任何运气。
该文件是在“www”文件夹中手动创建的 .txt 文件,通过使用 console.log 以及 .onerror 和 .onwriteend 事件函数,我可以看到作者应该完成了写入文件的任务成功,但文件的内容根本没有改变。
有谁知道这是什么原因?
这是来自 API 的示例(您可以在其中看到“readme.txt”,我使用了“/app/www/file.txt”):
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwriteend = function(evt) {
console.log("contents of file now 'some sample text'");
writer.truncate(11);
writer.onwriteend = function(evt) {
console.log("contents of file now 'some sample'");
writer.seek(4);
writer.write(" different text");
writer.onwriteend = function(evt){
console.log("contents of file now 'some different text'");
}
};
};
writer.write("some sample text");
}
function fail(error) {
console.log(error.code);
}