12-03-2017 12:22
12-03-2017 12:22
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.
12-04-2017 16:26
12-04-2017 16:26
Have you tried without the path, just the filename.
It works for me (using cbor)
12-04-2017 09:57
12-04-2017 09:57
Not sure why but the examples use .txt extensions even when they should be .json
There may be a limitation there, does switching away from .ini make any difference?
12-04-2017 10:22
12-04-2017 10:22
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.
12-04-2017 16:26
12-04-2017 16:26
Have you tried without the path, just the filename.
It works for me (using cbor)
12-05-2017 01:30
12-05-2017 01:30
As suggested by @Argy, remove the full path: just let resources/ as by default files will be written in /mnt/assets/. It will also work for the reading the file.
12-05-2017 12:48
12-05-2017 12:48
Hello 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
12-06-2017 04:45
12-06-2017 04:45
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.
12-06-2017 05:46
12-06-2017 05:46
The 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");
06-16-2018 13:31
06-16-2018 13:31
Hi,
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.