How can I save a object from TStringList class to file (Delphi XE 2) with UTF8 without BOM?

You simply have to set the property TStrings.WriteBOM to false.

The documentation tells us about this:

Will cause SaveToStream or SaveToFile to write a BOM.

Set WriteBOM to True to cause SaveToStream to write a BOM (byte-order mark) to the stream and to cause SaveToFile to write a BOM to the file.


You can achieve this by creating your own encoding class descended from TUTF8Encoding and overriding the GetPreamble method :-

type
  TUTF8EncodingNoBOM = class(TUTF8Encoding)
  public
    function GetPreamble: TBytes; override;
  end;

function TUTF8EncodingNoBOM.GetPreamble: TBytes; begin SetLength(Result, 0); end;