Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 1999-02-19 (08:27)
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.


- Xavier Leroy