Version française
Home     About     Download     Resources     Contact us    
Browse thread
Opening a file for both reading and writing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: Opening a file for both reading and writing
> Is it allowed to open a file for both reading and writing?

Yes, but you must be careful about calling flush at the right times.

> I opened the same file for reading and writing in 2 seperate
> channels. Some anomalies happened, e.g. reading from a position
> after overwriting some old data doesn't get the newly written
> value.

Probably you didn't call flush on the output channel to save buffered
writes to the disk file.  Just remember to flush each time you switch
from "write" mode to "read" mode, and you should be relatively safe.

Regards,

- Xavier Leroy