F
fjhst
Unregistered / Unconfirmed
GUEST, unregistred user!
问题很简单:使用TFileStream进行文件读写, 我往“d:/SomeFile.txt”写入字符串
'test!', 完后我又UltraEdit打开, 乱码,其ascii码:D0 6F 44 00 00, 而不是:
74 65 73 74 21('test!'), 我用的是WINDOWS 2000
代码如下:
procedure TForm1.Button5Click(Sender: TObject);
var
F: TFileStream;
str: PChar;
begin
str := 'test!';
F := TFileStream.Create('d:/SomeFile.txt', fmCreate);
F.Seek(0, soFromBeginning); // Vital! Do not forget!
F.Write(str, 5);
F.Free;
str:= ''; // This is additional line
F := TFileStream.Create('d:/ss.dat', fmOpenRead);
F.Seek(0, soFromBeginning); // Vital! Do not forget!
F.Read(str, 5);
showmessage(str);
F.free;
end;
请指点迷津, 谢谢!
'test!', 完后我又UltraEdit打开, 乱码,其ascii码:D0 6F 44 00 00, 而不是:
74 65 73 74 21('test!'), 我用的是WINDOWS 2000
代码如下:
procedure TForm1.Button5Click(Sender: TObject);
var
F: TFileStream;
str: PChar;
begin
str := 'test!';
F := TFileStream.Create('d:/SomeFile.txt', fmCreate);
F.Seek(0, soFromBeginning); // Vital! Do not forget!
F.Write(str, 5);
F.Free;
str:= ''; // This is additional line
F := TFileStream.Create('d:/ss.dat', fmOpenRead);
F.Seek(0, soFromBeginning); // Vital! Do not forget!
F.Read(str, 5);
showmessage(str);
F.free;
end;
请指点迷津, 谢谢!