电子包-如何写入/读取文件 [英] Electron package - how to write/read files
问题描述
我的应用程序根目录中有文件 test.txt
。使用命令 npm start
运行应用程序时,可以毫无问题地写入文件,但是当我使用电子打包程序进行打包时,无法将文本写入文件中再有-我遇到错误
I have file test.txt
in my root directory of app. When I run my app with command npm start
, I can write to my file without any problem, but when I make package using electron packager, writing text to my file is not possible anymore - I got error
错误:EACCES:权限被拒绝,请打开 ./test.txt
为此,我使用的是node.js文件系统:
For this, I'm using node.js filesystem:
fs.writeFile("./test.txt",text,function(err){
if(err) {
return alert(err);
}
alert("saved");
});
如何使其工作?打包过程后是否可以在我的应用程序中包含一些额外的文件夹?谢谢您的帮助!
How is possible to make this working? And is possible to include some extra folder in my app after package process? Thanks for your help!
推荐答案
并没有真正发现问题所在,因此我尝试了另一种解决方案,该解决方案适用于我(我的主要目的是将数据保存到应用程序的某些本地内存中)。
Didn't really found out what the problem was, so I tried another solution, which works for me (my main aim was to save data to some local memory of app).
我使用了npm软件包 electron-store
,它确实很容易使用。
I used npm package electron-store
which is really easy to use.
您可以通过在终端上键入此命令来获取它
You can get it by typing this to terminal
npm install electron-store
此处有更多信息:电子商店
希望它对其他人也有帮助:-)
Hope it helps someone else too :-)
这篇关于电子包-如何写入/读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!