Description
Use the ReadBytes
method to read data from a file and convert it to a sequence of bytes.
Declaration
aqBinaryFileObj.ReadBytes(Count)
aqBinaryFileObj | An expression, variable or parameter that specifies a reference to an aqBinaryFile object | |||
Count | [in] | Required | Variant | |
Result | aqBytes object
|
Applies To
The method is applied to the following object:
Parameters
The method has the following parameter:
Count
Result Value
The aqBytes
object that represents a sequence of obtained bytes. You can read and write individual bytes in it, as well as obtain the length of the sequence.
Remarks
To use this method, you need to open the needed file with the faRead
or faReadWrite
access permission. See the description of the OpenBinaryFile
method.
Example
The code below demonstrates how you can use the ReadBytes
method:
JavaScript, JScript
function Bytes()
{
Path = "C:\\MyFiles\FileName.txt";
// Reads the content of the specified file
myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead);
// Reads bytes from the file
s = myFile.ReadBytes();
myFile.Close();
// Writes the received array to the file
myFile = aqFile.OpenBinaryFile(Path, aqFile.faWrite, true);
result = myFile.WriteBytes(s);
myFile.Close();
}
Python
def Bytes():
Path = "C:\\MyFiles\FileName.txt"
# Reads the content of the specified file
myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead)
# Reads bytes from the file
s = myFile.ReadBytes()
myFile.Close()
# Writes the received array to the file
myFile = aqFile.OpenBinaryFile(Path, aqFile.faWrite, true)
result = myFile.WriteBytes(s)
myFile.Close()
VBScript
Sub Bytes
Dim Path, myFile, s, result
Set Path = "C:\\MyFiles\FileName.txt"
' Reads the content of the specified file
Set myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead)
Set s = myFile.ReadBytes()
Call myFile.Close()
' Writes the received array to the file
Set myFile = aqFile.OpenBinaryFile(Path, aqFile.faWrite, true)
Set result = myFile.WriteBytes(s)
Call myFile.Close()
End Sub
DelphiScript
procedure Bytes;
var Path, myFile, s, result;
begin
Path := 'C:\\MyFiles\FileName.txt';
// Reads the content of the specified file
myFile := aqFile.OpenBinaryFile(Path, aqFile.faRead);
// Reads bytes from the file
s := myFile.ReadBytes();
myFile.Close();
// Writes the received array to the file
myFile := aqFile.OpenBinaryFile(Path, aqFile.faWrite, true);
result := myFile.WriteBytes(s);
myFile.Close();
end;
C++Script, C#Script
function Bytes()
{
Path = "C:\\MyFiles\FileName.txt";
// Reads the content of the specified file
myFile = aqFile["OpenBinaryFile"](Path, aqFile.faRead);
// Reads bytes from the file
s = myFile["ReadBytes"]();
myFile["Close"]();
// Writes the received array to the file
myFile = aqFile["OpenBinaryFile"](Path, aqFile.faWrite, true);
result = myFile["WriteBytes"](s);
myFile["Close"]();
}
See Also
Working With Files From Scripts
WriteByte Method
ReadByte Method