cordova - Phonegap FileWrite 覆盖文件

标签 cordova overwrite filewriter

我正在尝试使用phonegap创建一个应用程序,但我遇到了FileWriter的问题。我正在创建一个文件,用户将包含数据。当用户第一次填写表单时,会创建一个包含数据的“.txt”文档。问题是,当再次使用不同的数据填写表单时,而不是在第一个文本之后写入,会覆盖文档。

我在phonegap文档中读到:

By default, the FileWriter writes to the beginning of the file, overwriting existing data. Set the optional append boolean to true in the FileWriter's constructor to write to the end of the file.

我不知道该怎么做...... 我留下了部分代码以防有帮助:

function writeXML(name, data){

            .createWriter(function gotFileWriter(writer) {

                fileWriter = writer;
                console.log("Getting writer...");

             }, fail);
        }, fail);

    while(fileWriter==null){
        //console.log("Waiting for file writer...");
    }
    fileWriter.onwriteend = function(evt) {
    console.log("File saved");
                            };
    fileWriter.write(data);}

非常感谢!

最佳答案

以防万一有人需要:

我只是添加

writer.seek(writer.length);

之后:

fileEntry.createWriter(function gotFileWriter(writer) {

它正在工作:D

关于cordova - Phonegap FileWrite 覆盖文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17809901/

相关文章:

java - 如何编写 JUnit 测试(用于文件写入)?

android - 音频焦点不是Cordova-plugin-multi-player的 “re Gained”

java - 针对特定情况覆盖 Java 中的 hashCode

python - 在写入文件之前删除文件的内容(在 Python 中)?

zend-framework - 覆盖 Zend_Config 并访问父节点

java - 在 While 循环中创建包含字符的字符串 Java

java - 如何将 JTable 的内容写入文本文件?

forms - jQuery 移动多页提交

jquery-mobile - 由于错误的后退按钮处理,Windows phonegap 应用程序认证失败

android - css3 transform rotate3d with perspective 不适用于Android