我正在尝试使用 phonegap filewriter API 将简单的文本“Hello”保存到文件中。我检查了在线文档和一些书籍(20 个 phonegap 食谱),但它仍然给我一个错误警报。以下是我的代码:
function SavetoFile(name, surname, mobilenumber, email, language, addressline1, addressline2, locality){
var fileWriter;
saveFile();
function onLoad(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSComplete, fail);
}
function onFSComplete(fileSystem){ // load file, create it if it doesn't exist
fileSystem.root.getFile("userdetails.txt", {create:true}. onFileEntryComplete, fail);
}
function onFileEntryComplete(fileEntry){ // set up a file writer
fileEntry.createWriter(onFileWriterComplete, fail);
}
function onFileWriterComplete(fileWriter){ // store the file writer in a global variable for when user presses save
fileWriter = fileWriter;
}
function saveFile(){
if(fileWriter != null){
fileWriter.onwrite = function(evt){
alert("Details Saved Successfully");
}
var fileline = "Hello";
fileWriter.write(fileline);
}
else{
alert("There was an error trying to save the file");
}
return false;
}
function fail(error) {
alert(error.code);
}
}
我正在调用主函数SavetoFile()并传递不同的参数。但是在使用它们之前,我想通过保存单词“Hello”来进行较小规模的测试,因此我在主函数中调用了另一个方法saveFile() 。这仍然给我一条错误消息。知道问题的根源可能是什么吗?