WriteData()

Syntax

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

Parameters

#File The file to write to.
*Buffer The memory address of the data to write to the file. It has to be allocated with AllocateMemory().
Size The number of bytes to write to the file.

Return value

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

Remarks

The file must be opened using a write-capable function (i.e. not with ReadFile()).

Example


  *Buffer = AllocateMemory(128)       ; allocating a memory block
  If *Buffer
    PokeS(*Buffer, 0, "Store this string in the memory area")   ; we write a string into the memory block (in UTF-8 format)
    If CreateFile(0, "Text.txt")          
      WriteData(0, *Buffer, 10)       ; write the first 10 chars from the memory block into the file
      
      ExportFile(0, "text/plain")
      CloseFile(0)                    ; close the previously opened file and so store the written data
    EndIf
  EndIf

See Also

ReadData(), CreateFile()

Supported OS

All

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