一 读出文件的长度
var
f: file of Byte;
size : Longint;
begin
AssignFile(f, f:\t.exe);
Reset(f);
size := FileSize(f);
edit1.text := IntToStr(size);
CloseFile(f);
end;
或:
var
fh:integer;
fs:longint;
begin
fh:=fileopen(文件名,fmopenread);
fs:=fileseek(fh,0,2);
fileclose(fh);
end;
二 将字符串用二进制模式写入文件
var
filehandle:integer;
filename:string;
fn:string;
begin
filehandle:=fileopen(filename,fmopenreadwrite);
fileseek(filehandle,i*256,0);
getmem(buffer,300);
try
strpcopy(buffer,fn);
filewrite(filehandle,buffer^,256);
finally
freemem(buffer);
end;
fileclose(filehandle);
end;
三 使用readln()从文件中读出超过255字符的字串
Type
{use longest line you may encounter here}
TLine = Array [0..1024] of Char;
PLine = ^TLine;
Var
pBuf: PLine;
...
New( pBuf );
...
ReadLn( F, pBuf^ );
四 向文本文件后追加一行
var
filevar: textfile;
buf:string;
begin
assignfile(filevar,txt.log);
append(filevar);
writeln(filevar,buf);
closefile(filevar);
end;