android - phonegap filewriter 追加问题

标签 android cordova

尝试使用 phonegap 0.9.6 文件存储。该代码在我编写文件时工作正常,但在我尝试附加到文件(使用搜索、截断等)时不起作用。

版本 0.9.5 中有一个错误似乎已修复。

代码在我调用 writer.seek 时终止。截断后的警报(或者如果我删除截断搜索)根本没有被调用。

我应该在某处设置附加标志吗?该文档说但没有给出我应该在哪里设置追加标志的示例。代码如下

function gotFS(fileSystem) {
        fileSystem.root.getFile( "test.txt", {"create":true,
            "exclusive":false}, gotFileEntry, fail);
    }

    function gotFileEntry(fileEntry) {
        fileEntry.createWriter(gotFileWriter, fail);
    }

    function gotFileWriter(writer) {
        writer.onwrite = function(evt) {
            console.log("write success");
        };

        writer.write("some sample text");
        // contents of file now 'some sample text'
        writer.truncate(11);
        alert('truncated');
        // contents of file now 'some sample'
        writer.seek(writer.length); //writer.seek(4) does not work either

        // contents of file still 'some sample' but file pointer is after the 'e' in 'some'
        writer.write(" different text");
        // contents of file now 'some different text'
        alert('success with diff text');
    }

如有任何帮助,我们将不胜感激。

最佳答案

我找到了解决方法:

        function gotFileWriter(writer) {
            writer.onwrite = function(evt) {
                console.log("write success");
            };

            writer.write("some sample text");
            // contents of file now 'some sample text'
            writer.abort();
            writer.truncate(11);
            // contents of file now 'some sample'
            writer.abort();
            writer.seek(writer.length); //writer.seek(4) does not work either

            // contents of file still 'some sample' but file pointer is after the 'e' in 'some'
            writer.write(" different text");
        }

关于android - phonegap filewriter 追加问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6874398/

相关文章:

android - ImageView setMargins 不起作用

java - 请求自动或用户选择适当的客户端证书

android - 适用于 Android 设备(和 iOS)的 CouchDB 安全性

cordova - 努力打开我从 GitHub 克隆的现有 ionic 项目并理解 .iceproj 与 ionic.project 文件

html - 纯 html5 与 jquery 移动/angularjs

android - 哪个android文件夹到夜间模式的资源,v21 +?可绘制之夜-v21?

javascript - 使用 Visual Studio 2015 在 Apache Cordova 中打开缺少 exec :SQLitePlugin.

ios - Phonegap/Cordova 文件传输上传图像作为 Base64 字符串在 ios 中不起作用

javascript - 清除 Backbone.history

android - 创建可下载的自定义主题并在运行时应用它