I'm on Windows 10, trying to read and write a simple text file using Tabris.js
console.log reports:
/local/src/hello.txt
Error: No such file or directory: /local/src/hello.txt
CODE:
const {fs} = require('tabris');
let path=fs.filesDir + '/src/hello.txt'
console.log(path)
fs.writeFile(path, 'Hello World!', 'ascii')
.then(() => console.log('file written:', path))
.catch(err => console.error(err));
Tabris.js reference:
Clarification:
If I get this to work, I'm going to do a very simple tutorial.
Tabris runs fine with no issues, but I can't read or write a file because of the error finding the file. I've tried a dozen combinations of things, with dots, no dots etc. - no luck. Tried __directory, fs.filesDir etc. so path wouldn't be hard coded, nothing working.
Tabris folders and file location:
C:\Users\Rob Acer Aspire 3\junk\package.json
C:\Users\Rob Acer Aspire 3\junk\src\app.js
Tabris 2.4
Thanks for all the help.
UPDATE- got it working...
It seems to work now, with code below. I was assuming that hello.txt would be in my /src folder, or at least me tabris folder called 'junk' but it is writing to another folder. It seems that the docs are correct on this as they say The path of a directory that the app may use to store persistent files.
let file = fs.filesDir + '/hello.txt';
// ok, this works.. > file written: /local/hello.txt
// and is located in:
// C:\Users\Rob Acer Aspire 3\AppData\Local\Packages\EclipseSource.Tabris.js2_en185yn5qwkmw\LocalState\hello.txt
I didn't understand what /local/hello.txt
really meant
So, my question is answered, thanks for help.
Rob