xHarbour Reference Documentation > Function Reference |
Closes a binary file.
FClose( <nFileHandle> ) --> lSuccess
The return value is .T. (true) when the file is successfully closed, otherwise .F. (false).
FClose() closes a file that is either newly created with FCreate() or opened with FOpen(). Both functions return a numeric file handle that must be passed to FClose() in order to close the open file. When the file is successfuly closed, all internal file buffers are permanently written to disk, and the function returns .T. (true).
If the close operation fails, the return value is .F. (false). The reason for failure can then be queried by calling the FError() function.
See also: | FCreate(), FError(), FOpen(), FRead(), FSeek(), FWrite() |
Category: | File functions , Low level file functions |
Source: | rtl\philes.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates how to create a new file, write // some data to it and close it. If any operation fails, an // appropriate error message is displayed along with the error // code obtained from the operating system. #include "Fileio.ch" PROCEDURE Main LOCAL nFileHandle, cText nFileHandle := FCreate( "NewFile.txt", FC_NORMAL ) IF FError() <> 0 ? "Error while creatingg a file: ", FError() QUIT ENDIF cText := "New text for file" IF FWrite( nFileHandle, cText ) <> Len( cText ) ? "Error while writing a file: ", FError() ENDIF IF .NOT. FClose( nFileHandle ) ? "Error while closing a file: ", FError() ELSE ? "File successfully created and closed" ENDIF RETURN
http://www.xHarbour.com