Can anybody give some sample code to read and write a file using JavaScript?
No. Browser-side javascript doesn't have permission to write to the client machine without a lot of security options having to be disabled