System.IOUtils.TFile.ReadAllText

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

class function ReadAllText(const Path: string): string; overload; inline; static;
class function ReadAllText(const Path: string;
const Encoding: TEncoding): string; overload; inline; static;

C++

static System::UnicodeString __fastcall ReadAllText(const System::UnicodeString Path)/* overload */;
static System::UnicodeString __fastcall ReadAllText(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.

ReadAllText reads the contents of a textual file and returns a string containing the text read from the file.

ReadAllText, with one parameter, first reads the preamble bytes from the beginning of the Path textual file. Then ReadAllText skips the preamble bytes and reads the contents of the textual file beginning from this offset. ReadAllText returns a string containing the text read 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 corresponding number of bytes is skipped.

ReadAllText, 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 containing the text read from the file.

ReadAllText has the following parameters:

  • Path is the path to the file.
  • Encoding is the encoding of the text contained within the Path file.
Notes:
  • A preamble is a sequence of bytes that specifies the encoding used. It is known as Byte Order Mark (BOM).
  • ReadAllText raises an exception if the file cannot be opened or the path is invalid.
  • If the specified encoding differs from the actual encoding of the file, the return value is undefined. In some cases, an EEncondingError exception is raised. For example, opening an ANSI file with accented characters as UTF8 returns an unpredictable string with garbage characters or generates an EEncondingError exception.

See Also

Code Examples