PhoneGap的FileWriter的追加问题 [英] phonegap filewriter append issue

查看:118
本文介绍了PhoneGap的FileWriter的追加问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用PhoneGap的0.9.6文件存储。在code,而我写一个文件,但是当我尝试添加到该文件(使用寻求,截断等)无法正常工作正常工作。

Trying to use phonegap 0.9.6 file storage. The code works fine while I am writing a file but does not work when I try to append to the file (using seek, truncate etc.).

有在0.9.5版本,这似乎是固定的错误。

There was a bug in version 0.9.5 that seems to be fixed.

当我打电话writer.seek的code只是终止。警报后截断(或者,如果我删除寻求截断)不会被调用的。

The code just terminates when I call writer.seek. The alert after truncate (or if I delete the truncate the seek) is not being called at all.

我应该设置一个附加标志的地方?美国商务部说,但不举一个例子来,我应该设置追加标志。在code是如下:

Should I set an append flag somewhere? The doc says that but does not give an example as to where I should be setting the append flag. The code is as follows

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');
    }

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

我发现了一个解决方法到:

I found a workaround to that :

        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");
        }

这篇关于PhoneGap的FileWriter的追加问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆