Description
Declaration
aqTextFileObj.ReadLine()
aqTextFileObj | An expression, variable or parameter that specifies a reference to an aqTextFile object | |||
Result | String |
Applies To
The method is applied to the following object:
Result Value
A string containing the text from the cursor position to the end of the current line.
Remarks
-
ReadLine
uses Windows line breaks – CR+LF (\r\n
or 0x0D0A). CR or LF alone is not recognized as a line break. -
If successful, the
Cursor
position is moved to the beginning of the next line.
Example
The code below reads a text file by lines and posts each line to the test log.
JavaScript, JScript
function ReadTextFromFile()
{
var sPath = "D:\\Files\\MyFile.txt";
// Opens the specified file for reading
var myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode);
Log.Message("File by lines:");
// Reads text lines from the file and posts them to the test log
while(! myFile.IsEndOfFile())
{
s = myFile.ReadLine();
Log.Message(s);
}
// Closes the file
myFile.Close();
}
Python
def ReadTextFromFile():
sPath = "D:\Files\MyFile.txt"
# Opens the specified file for reading
myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode)
Log.Message("File by lines:")
# Reads text lines from the file and posts them to the test log
while not myFile.IsEndOfFile():
s = myFile.ReadLine()
Log.Message(s)
# Closes the file
myFile.Close()
VBScript
Sub ReadTextFromFile
Dim sPath, myFile, s
sPath = "D:\Files\MyFile.txt"
' Opens the specified file for reading
Set myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode)
Log.Message("File by lines:")
' Reads text lines from the file and posts them to the test log
While Not myFile.IsEndOfFile()
s = myFile.ReadLine()
Call Log.Message(s)
WEnd
' Closes the file
Call myFile.Close()
End Sub
DelphiScript
procedure ReadTextFromFile;
var sPath, myFile, s;
begin
sPath := 'D:\Files\MyFile.txt';
// Opens the specified file for reading
myFile := aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode);
Log.Message('File by lines:');
// Reads text lines from the file and posts them to the test log
while not myFile.IsEndOfFile() do
begin
s := myFile.ReadLine();
Log.Message(s);
end;
// Closes the file
myFile.Close();
end;
C++Script, C#Script
function ReadTextFromFile()
{
var sPath = "D:\\Files\\MyFile.txt";
// Opens the specified file for reading
var myFile = aqFile["OpenTextFile"](sPath, aqFile.faRead, aqFile.ctUnicode);
Log["Message"]("File by lines:");
// Reads text lines from the file and posts them to the test log
while(! myFile.IsEndOfFile())
{
s = myFile["ReadLine"]();
Log["Message"](s);
}
// Closes the file
myFile["Close"]();
}
See Also
Working With Files From Scripts
Write Method
WriteLine Method
ReadAll Method
ReadToSymbol Method
ReadString Method