Description
The ReadByte
method retrieves one byte from a binary file (starting from the current cursor position) and treats it as an integer value.
Declaration
aqBinaryFileObj.ReadByte()
aqBinaryFileObj | An expression, variable or parameter that specifies a reference to an aqBinaryFile object | |||
Result | Integer |
Applies To
The method is applied to the following object:
Result Value
The integer value read from the file.
Remarks
On success, the cursor position is shifted by one byte.
Keep in mind that writing an integer value shifts the cursor position either by 4 or by 8 bytes, whereas reading an integer value can shift the position by 1-8 bytes depending on the method used.
Example
The code below demonstrates how you can use the ReadByte
method to read all the data from a binary file.
JavaScript, JScript
function ReadingFileContent()
{
// Opens the file for reading
MyFile=aqFile.OpenBinaryFile("C:\\MyFiles\\FileName.txt", aqFile.faRead);
// Reads the file content
while (!MyFile.IsEndOfFile () );
{
Log.Message(MyFile.ReadByte());
}
// Closes the file
MyFile.Close();
}
Python
def ReadingFileContent():
# Opens the file for reading
MyFile=aqFile.OpenBinaryFile("C:\\MyFiles\\FileName.txt", aqFile.faRead)
# Reads the file content
while not MyFile.IsEndOfFile():
Log.Message(MyFile.ReadByte())
# Closes the file
MyFile.Close()
VBScript
Sub ReadingFileContent
' Opens the file for reading
Set MyFile=aqFile.OpenBinaryFile("C:\MyFiles\FileName.txt", aqFile.faRead)
' Reads the file content
While Not MyFile.isEndofFile
Log.Message(MyFile.ReadByte)
Wend
' Closes the file
MyFile.Close
End Sub
DelphiScript
procedure ReadingFileContent;
var MyFile: OleObject;
begin
// Opens the file for reading
MyFile:=aqFile.OpenBinaryFile('C:\MyFiles\FileName.txt', aqFile.faRead);
// Reads the file content
while not MyFile.IsEndOfFile() do
begin
Log.Message(MyFile.ReadByte);
end;
// Closes the file
MyFile.Close();
end;
C++Script, C#Script
function ReadingFileContent()
{
// Opens the file for reading
MyFile=aqFile["OpenBinaryFile"]( "C:\MyFiles\FileName.txt", aqFile.faRead );
// Reads the file content
while (! MyFile["IsEndOfFile"]() )
{
Log["Message"]( MyFile["ReadByte"]() );
}
// Closes the file
MyFile ["Close"]();
}
See Also
Working With Files From Scripts
WriteByte Method
ReadBytes Method
ReadInt Method
ReadShort Method
ReadCurrency Method
ReadInt64 Method
ReadFloat Method
ReadString Method
ReadBool Method
ReadDate Method