尝试使用 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/