| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Writes data to an open binary file.
FWrite( <nFileHandle>, ;
<cBuffer> , ;
[<nBytes>] , ;
[<nOffset>] ) --> nBytesWritten
The function returns a numeric value which is the number of bytes written to the file. If the return value equals <nBytes>, the operation was succesful. Any value differeing from <nBytes> indicates failure, which can be identified using function FError().
The low-level file function FWrite() writes data provided in form of a character string into an open file. Data is written starting at the current position of the file pointer. The file pointer is advanced to a new position by the number of written bytes.
| See also: | FClose(), FCreate(), FError(), FOpen(), FRead(), FReadStr(), FWrite() |
| Category: | File functions , Low level file functions |
| Source: | rtl\philes.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example implements the user defined function WriteStream()
// which writes an entire character string into a newly created file
PROCEDURE Main
LOCAL aDir := Directory()
LOCAL cFiles := ""
AEval( aDir, {|a| cFiles += a[1] + Chr(13)+Chr(10) } )
IF .NOT. WriteStream( "Files.txt", cFiles )
? "Error writing file", FError()
ENDIF
RETURN
FUNCTION WriteStream( cFile, cStream )
LOCAL nHandle := FCreate( cFile )
IF FError() <> 0
RETURN .F.
ENDIF
FWrite( nHandle, cStream, Len(cStream) )
FClose( nHandle )
RETURN ( FError() == 0 )
http://www.xHarbour.com