本文整理自网络,侵删。
读取UTF-8格式的文件内容
function LoadUTF8File(AFileName: string): string;
var ffileStream:TFileStream;
fAnsiBytes: string;
S: string;
begin
ffileStream:=TFileStream.Create(AFileName,fmOpenRead);
SetLength(S,ffileStream.Size);
ffileStream.Read(S[1],Length(S));
fAnsiBytes:= UTF8Decode(Copy(S,4,MaxInt));
Result:= fAnsiBytes;
end;
写入UTF-8编码格式的文件
procedure SaveUTF8File(AContent:string;AFileName: string);
var ffileStream:TFileStream;
futf8Bytes: string;
S: string;
begin
ffileStream:=TFileStream.Create(AFileName,fmCreate);
futf8Bytes:= UTF8Encode(AContent);
S:=#$EF#$BB#$BF;
ffileStream.Write(S[1],Length(S));
ffileStream.Write(futf8Bytes[1],Length(futf8Bytes));
ffileStream.Free;
end;
相关阅读 >>
Delphi firedac 如何按整型(byte)读取 mysql tinyint(1) 类型字段?
Delphi windows 下用 Delphi 代码杀死进程,或者杀死自己
Delphi dcc64.exe Delphi64位命令行编译器揭秘
更多相关阅读请进入《Delphi》频道 >>