一 讀出文件的長度
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;