System.IOUtils.TFile.WriteAllText

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

class procedure WriteAllText(const Path, Contents: string); overload; static;
class procedure WriteAllText(const Path, Contents: string;  const Encoding: TEncoding); overload; static;

C++

static void __fastcall WriteAllText(const System::UnicodeString Path, const System::UnicodeString Contents)/* overload */;
static void __fastcall WriteAllText(const System::UnicodeString Path, const System::UnicodeString Contents, System::Sysutils::TEncoding* const Encoding)/* overload */;

Properties

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

Description

Encodes the given Contents text and writes the obtained text into the Path text file.

WriteAllText, with one parameter, first creates the Path file, then encodes the specified Contents string using the UTF8 encoding, and then writes the encoded string into the created text file.

WriteAllText, with two parameters, first creates the Path file, then writes the preamble describing the specified Encoding encoding into the created file, then encodes the specified Contents string using the specified Encoding encoding, and then appends the encoded string into the Path file.

If the file specified by the Path parameter exists, it is overwritten; otherwise the file is created and filled with the given text.

WriteAllText has the following parameters:

  • Path is the path to the file.
  • Contents is the string containing the text to be written.
  • Encoding is the encoding to be used for the text.
Note: A preamble is a sequence of bytes that specifies the encoding used. It is known as Byte Order Mark (BOM).
Note: WriteAllText raises an exception if the file cannot be accessed or the path is invalid.

See Also

Code Examples