WriteData()

Syntax

Result = WriteData(#File, *MemoryBuffer, Length)
Description
Write the content of the specified memory buffer to a file.

Parameters

#File The file to write to.
*MemoryBuffer The memory address of the data to write to the file.
Length The number of bytes to write to the file. The maximum length is 2 GB.

Return value

Returns the number of bytes actually written to the file. If there is an error, the return-value is zero.

Remarks

Because of file buffering, this function may return successful even if there is not enough space left on the output device for the write operation. The file must be opened using a write-capable function (i.e. not with ReadFile()).

Example


  *MemoryID = AllocateMemory(1000)       ; allocating a memory block
  If *MemoryID
    PokeS(*MemoryID, "Store this string in the memory area")   ; we write a string into the memory block
  EndIf
  If CreateFile(0, GetHomeDirectory()+"Text.txt")           ; we create a new text file...
    WriteData(0, *MemoryID, SizeOf(Character)*Len("Store this string in the memory area"))          ; write the text from the memory block into the file
    CloseFile(0)                         ; close the previously opened file and so store the written data
  Else
    Debug "may not create the file!"
  EndIf

See Also

ReadData(), CreateFile(), OpenFile()

Supported OS

All

<- WriteCharacter() - File Index - WriteDouble() ->