Javascript – How to read and write into file using JavaScript


Can anybody give some sample code to read and write a file using JavaScript?

Best Solution

For completeness, the OP does not state he is looking to do this in a browser (if he is, as has been stated, it is generally not possible)

However javascript per se does allow this; it can be done with server side javascript.

See this documentation on the Javascript File class

Edit: That link was to the Sun docs that now have been moved by Oracle.

To keep up with the times here's the node.js documentation for the FileSystem class:

Edit(2): You can read files client side now with HTML5: