How to read and write into file using JavaScript?

ABC picture ABC · Feb 25, 2009 · Viewed 476k times · Source

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

Answer

DanSingerman picture DanSingerman · Feb 25, 2009

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: http://nodejs.org/docs/latest/api/fs.html

Edit(2): You can read files client side now with HTML5: http://www.html5rocks.com/en/tutorials/file/dndfiles/