0

我一直在尝试使用 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);
}
4

1 回答 1

2

我不是 100% 确定 WP7,但在其他平台上,您不能写入 www 目录,因为它是您的应用程序的只写部分。我确定这段代码可以正常工作,但它正在写入您的持久文件存储。

于 2012-04-16T19:00:56.630 回答