Electron fs.writeFile - 多次保存文件时出现问题
Electron fs.writeFile - Problems saving the file more than once
我正在将 json 保存到这样的文件中:
首先我JSON.stringify
数据...然后...
fs.writeFile('myjson.json', contenthere, 'utf8', function(err) {
if(err) {
return console.log(err);
}
console.log('File was saved');
});
这实际上是在保存文件,我没有收到任何错误,但它不会再次加载或再次保存。
就像我只允许做一次但没有错误。
是否有更好的替代方案以便我可以尝试或对可能出现的问题有任何想法?
这可能更多是节点问题,而不是电子问题。来自文档:
Note that it is unsafe to use fs.writeFile multiple times on the same
file without waiting for the callback. For this scenario,
fs.createWriteStream is strongly recommended.
因此,改为研究 fs.createWriteStream 方法。
Link 到 docs.
我正在将 json 保存到这样的文件中:
首先我JSON.stringify
数据...然后...
fs.writeFile('myjson.json', contenthere, 'utf8', function(err) {
if(err) {
return console.log(err);
}
console.log('File was saved');
});
这实际上是在保存文件,我没有收到任何错误,但它不会再次加载或再次保存。
就像我只允许做一次但没有错误。
是否有更好的替代方案以便我可以尝试或对可能出现的问题有任何想法?
这可能更多是节点问题,而不是电子问题。来自文档:
Note that it is unsafe to use fs.writeFile multiple times on the same file without waiting for the callback. For this scenario, fs.createWriteStream is strongly recommended.
因此,改为研究 fs.createWriteStream 方法。
Link 到 docs.