System.IOUtils.TFile.ReadAllLines

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

class function ReadAllLines(const Path: string): TStringDynArray;
class function ReadAllLines(const Path: string;
const Encoding: TEncoding): TStringDynArray; overload; static;

C++

static System::TStringDynArray __fastcall ReadAllLines(const System::UnicodeString Path)/* overload */;
static System::TStringDynArray __fastcall ReadAllLines(const System::UnicodeString Path, System::Sysutils::TEncoding* const Encoding)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
System.IOUtils.pas
System.IOUtils.hpp
System.IOUtils TFile

Description

Returns the contents of a textual file as a string array.

ReadAllLines reads the contents of a textual file and returns a string array containing the retrieved text lines.

ReadAllLines, with one parameter, first reads the preamble bytes from the beginning of the Path textual file. Then ReadAllLines skips the preamble bytes and reads the contents of the textual file beginning from this offset. ReadAllLines returns a string array containing the text lines retrieved from the file.
If the Path file does not contain a byte order mark for one of the standard encodings, the Default standard encoding is accepted and the corresponding number of bytes is skipped.

ReadAllLines, with two parameters, first reads from the beginning of the Path textual file and skips the number of bytes corresponding to the preamble of the specified Encoding. Then ReadAllText reads the contents of the textual file beginning from this offset and returns a string array containing the text lines retrieved from the file.

ReadAllLines has the following parameters:

  • Path is the path to the file.
  • Encoding is the encoding of the text contained within the Path file.
Note: A preamble is a sequence of bytes that specifies the encoding used. It is known as Byte Order Mark (BOM).
Note: ReadAllLines raises an exception if the file cannot be opened or the path is invalid.
Note: ReadAllLines may throw an EEncodingError exception when specifying the wrong encoding. For example, opening a file that contains extended ASCII characters encoded as ANSI but specifying UTF8 as encoding will likely result in an EEcondingError exception.

See Also