|
WriteData
int WriteData(string
filename, array data)
Return
Value
Returns OK if data was written
successfully. Otherwise returns FAIL.
Returns array of bytes that represents
the content of the file. If the file does not exist or read
operation failed the size of result array is 0.
Parameters
filename
– the name of
the file.
data
-
array of bytes
that needs to be written to the file.
Remarks
Writes binary
data to the file indicated by filename. The function does
not close file. Use CloseFile function
to close the file. Note that this function does not create the
folder specified in the filename. If a folder does not exist the
function will fail. Use CreateDir function to create a
folder.
Package
Plug in module:
nd_fileplg.npl
Example
The following
example demonstrates the use of WriteData.
# Example for WriteData
# this script
opens the log file, seeks to
# the end and
appends the data
string sFileName = "C:\log.txt"
array Response
int nSocket = OpenTCPConnection("mail.netmechanica.com", 110)
if(nSocket != FAIL)
Sleep(2)
if
(IsDataAvailable(nSocket))
Response =
ReadTCPData(nSocket)
if(SeekToEnd(sFileName) != FAIL)
if(WriteData(sFileName, Response) == OK
Println("Data written
successfully")
else
Println("Error writing data")
endif
endif
CloseFile(sFileName)
endif
CloseSocket(nSocket)
endif
|