1. Use [code][/code] tags when posting code.

2. Why are you trying to read and write to the file at the same time?