1

I have a text file like this:

settings:value
data:integer:boolean
data:integer:boolean
data:integer:boolean
data:integer:boolean
...

I need CRUD operations over this text file using javascript. This file is in the same js file's directory.

EDIT after some comments: This is for a Firefox addon. Maybe we can count with more privileges?

14
  • Are you talking client-side JS, with the file in the same directory on the server? Commented Nov 28, 2011 at 18:14
  • 4
    You can't. JavaScript can't edit external files, it can only read them. Commented Nov 28, 2011 at 18:14
  • client-side JS. No server side interaction Commented Nov 28, 2011 at 18:15
  • 2
    You might want to investigate the HTML5 web storage facilities. Only in newer browsers. Commented Nov 28, 2011 at 18:17
  • 1
    If it is a firefox addon, you should tag it as such - quite a different question in that light. See: developer.mozilla.org/en/Code_snippets/File_I%2F%2FO Commented Nov 28, 2011 at 20:07

2 Answers 2

1

With the FileSystem API... but it will only work on Chrome :(

Other browsers will allow you to read files using the HTML5 File API, but only Chrome will let you write.

Sign up to request clarification or add additional context in comments.

4 Comments

It also only works on local client-side files, not remote ones.
@mblase75 - I think that's what he's asking for: the OP commented above says "client-side JS. No server side interaction"
Yes, It must be a text file (in the client-side -for a Firefox addon-) This addon interacts with a desktop app. The desktop app writes this file and the FF addon read each line and mark one by one as executed.
@NomikOS - There's an article on MDN about File I/O which is tagged "extensions"... but I'm not sure if it is deprecated.
1

SOLVED
YES! It is possible read and write text files in a privileged ambient as it is inside a Firefox addon.
The best solution I have found is using: Basic JavaScript File and Directory IO module and here is a little tutorial about it: File I/O with Firefox Add-ons

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.