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

Answer: 
The future is here! The proposals are closer to completion, no more ActiveX or flash or java. Now we can use:

* [File System APIs](https://developer.mozilla.org/en-US/docs/Web/API/File_and_Directory_Entries_API)
* [Native Drag&Drop File Access](https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API)

You could use the Drag/Drop to get the file into the browser, or a simple upload control. Once the user has selected a file, you can read it w/ Javascript: <http://www.html5rocks.com/en/tutorials/file/dndfiles/>
For Firefox:

```
var file = Components.classes["@mozilla.org/file/local;1"].
       createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/home");

```

See <https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O>

For others, check out the [TiddlyWiki](http://www.tiddlywiki.com/) app to see how it does it.