System.IOUtils.TFile.WriteAllLines

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

class procedure WriteAllLines(const Path: string;  const Contents: TStringDynArray); overload; inline; static;
class procedure WriteAllLines(const Path: string;  const Contents: TStringDynArray; const Encoding: TEncoding); overload; static;

C++

static void __fastcall WriteAllLines(const System::UnicodeString Path, const System::DynamicArray<System::UnicodeString> Contents)/* overload */;
static void __fastcall WriteAllLines(const System::UnicodeString Path, const System::DynamicArray<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

Writes the given Contents string array to the Path text file.

WriteAllText, with one parameter, first creates the Path file, then retrieves the string from the the specified Contents string array and encodes this 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 retrieves the string from the the specified Contents string array and encodes this string using the specified Encoding encoding, and then appends the encoded string to the text file.

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

WriteAllLines has the following parameters:

  • Path is the path to the file.
  • Contents is the array of strings 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: WriteAllLines raises an exception if the file cannot be accessed or the path is invalid.

See Also