This is just an example code. This is part of a bigger project. I just wanted to make things a little more simple so I just took out the problem area and posted it here. When i run this code it does not work with any file greater then 16K, I don't know why. I think it may have to do something with buffers but I tried using syswrite and sysread but it doesn't help.