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