

This releases the file as resource and - in case of a file opened for writing - flushes the associated buffer, ensures the file consistency in the file system, and thus makes the file available for other processes and applications. Closing a fileĪs soon a s you don't need to write or read to/from a file any longer you should make sure to close the file using procedure fileClose (with the file handle as argument). Any of these subroutines are illegal if the file handle is 0 or negative or if it was not obtained by an opening function, if the kind of access doesn't match or if the associated file has already been closed inbetween. a valid file handle) then you may apply the appropriate file-related functions or procedures, always providing the file handle as first argument. You should always test whether you obtained a valid handle by the applied opening function! If you obtained a positive number (i.e. -2: file not found (in case of fileOpen).

Numbers greater than zero are valid file handles whereas numbers less than or equal to zero signal that the open attempt failed: as output file), which requires writing permissions, of course.Īny of the three opening routines returns an integer value, which in case of success serves as program-internal identifier and file handle for all the access operations you may perform with the opened file.

Closing of the file as soon as access is completed.Access to the content according to the requested access type.Opening of the file for the intended access type (read / write).A program that is to work with some file will have to observe the following mandatory phases: A file is a resource administered by the operating system (OS), situated in the file system and identified there by a file path.
