Hi everybody,
I try to write and read some app settings to a file on my ionic.
While the reading with
fs.readFileSync("/mnt/assets/resources/myFile.ini", "utf-8");
works without problems the write command
fs.writeFileSync("/mnt/assets/resources/myFile.ini", tmpString, "utf-8");
within the same app doesn't work.
The write command always shows the error "Couldn't open file: /mnt/assets/resources/myFile.ini" while the read command just a few lines later work with the same file and filename...
Does anybody have an idea?
Capitano
Answered! Go to the Best Answer.
Best AnswerHave you tried without the path, just the filename.
It works for me (using cbor)
yes - I also tried the examples literally already - with filetype ascii and name "ascii.txt" - brings the same error, too.
I wondered if it's necessary to grant access for writing to the device, but couldn't find anything in this direction.
I also wondered if it could be possible to create a file in the code or if it would be created by using the writeFileSync-function if it doesn't exist - - but as mentioned a these thoughts are theoratical - writing doesn't work at all.
Best AnswerHello all,
just a short feedback: In my app now the suggestion of @agsurf5 works with both the writing and the reading. Unfortunately all combinations with a part of the filepath don't work - also the "resources/myFile.ini" naming doesn't.
Thanks a lot
Capitano
The relative path (start at project roots) should work for reading and writing. As an example, if I create a folder named data in the resources folder, I will be able to access it with
let utf8_read = fs.readFileSync("resources/data/myFile.ini", "utf-8");
If it's still not working, feel free to send me the export of your project in private and I'll give it a closer look.
Best AnswerThe relative path *should* work (and might now in the more recent firmware), but I had to do this to access a file:-
var stats = fs.statSync("/mnt/assets/resources/level_data.bin");
Best AnswerHi,
I know this topic is old and marked as solved but I'd just like to mention another little (non obvious) undocumented feature I just discovered that will cause the exact same issue,
Anything you put in your app's resources folder that gets copied into the finished zip is write-protected. And it's impossible to override this protection in code.
So, if you want to have a little settings.txt file to read from and write to, you must initially generate it in code. Otherwise you'll never get write access to your file.
Hope this helps someone.