【发布时间】:2018-09-03 22:11:18
【问题描述】:
我正在尝试在电子应用程序中创建备份系统,用户可以在其中选择要使用对话框导入的数据库文件。它应该复制您选择的文件并将其替换为当前文件(如果存在)。我正在使用 SQLite 和 angularjs。我的功能是这样的
$scope.load = function(){
dialog.showOpenDialog((fileNames) => {
//select file
if(fileNames === undefined){
console.log("No file selected");
return;
}
//read it
fs.readFile(fileNames[0], 'utf8', (err, data) =>{
if(err){
alert("An error ocurred reading the file :" + err.message);
return;
}
//copy file content into existing database file
fs.writeFile(dbLocation, data, (err) =>{
if (err) {
alert("An error ocurred updating the file" + err.message);
console.log(err);
return;
}
alert("The file has been succesfully saved");
});
});
});
}
我根据一些教程构建了这段代码,它完美地复制了文件内容,但奇怪的是它本身添加了一些标志或其他东西。这会导致该数据库文件已损坏或无法读取。 从替换文件读取后出现此错误。
【问题讨论】: