我一直试图让一个应用程序使用phonegap / cordova API中的示例,在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);
}
答案 0 :(得分:2)
我不是百分之百确定WP7,但在其他平台上你不能写入www目录,因为它只是你应用程序的只写部分。我确信这段代码正在运行,但它正在写入你的持久性文件存储。