|
ReadData
array ReadData(string
filename, int count)
Return
Value
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.
count
- the maximum number of bytes to be read from the file or -1 to
read all bytes.
Remarks
Call this
function to read data from the file into a byte array.
Note that
calling this function repositions the read pointer in the file by
the number of bytes that have been read. In order to shift the read
pointer to the beginning of the file you need to close the file
first using CloseFile function.
Package
Plug in module:
nd_fileplg.npl
Example
The following
example demonstrates the use of ReadData.
# Example for
ReadData
string sFileName =
"c:\1.txt"
string sResult
array Bytes
if(IsFileExist(sFileName)
== FALSE)
Println("File ", sFileName,
" does not exist")
stop
endif
Bytes =
ReadData(sFileName, -1)
int nBytes =
GetArraySize(Bytes)
Println("Bytes read = ",
nBytes)
for(int i=0;i<nBytes;i++)
sResult +=
Bytes[i]
endfor
CloseFile(sFileName)
Println(sResult)
Output of the example
script:
Bytes read = 30
Hello World!!!
My name is Bob.
|