Can anybody give some sample code to read and write a file using JavaScript?
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/
2.1m questions
2.1m answers
60 comments
57.0k users