var myfile:textfile; temp:string; if fileexists('xxx.txt') then begin try AssignFile(myfile,'xxx.txt');//这一步是将文件名赋给MYFILE reset(myfile); readln(myfile,temp); finally closefile(myfilefile); end; end;
function FileIsThere(FileName: string): Boolean;{ Boolean function that returns True if the file exists; otherwise, it returns False. Closes the file if it exists. } var F: file; begin {$I-} AssignFile(F, FileName); FileMode := 0; {Set file access to read only } Reset(F); CloseFile(F); {$I+} FileIsThere := (IOResult = 0) and (FileName <> ''); end; { FileIsThere }begin if FileIsThere(ParamStr(1)) then {Get file name from command line} Canvas.TextOut(10, 10, 'File exists') else Canvas.TextOut(10, 10, 'File not found'); end;
一般的,在使用reset打开文件之前,需要先调用assignfile
temp:string;
if fileexists('xxx.txt') then begin
try
AssignFile(myfile,'xxx.txt');//这一步是将文件名赋给MYFILE
reset(myfile);
readln(myfile,temp);
finally
closefile(myfilefile);
end;
end;
it returns False. Closes the file if it exists. }
var
F: file;
begin
{$I-}
AssignFile(F, FileName);
FileMode := 0; {Set file access to read only }
Reset(F);
CloseFile(F);
{$I+}
FileIsThere := (IOResult = 0) and (FileName <> '');
end; { FileIsThere }begin if FileIsThere(ParamStr(1)) then {Get file name from command line}
Canvas.TextOut(10, 10, 'File exists')
else
Canvas.TextOut(10, 10, 'File not found');
end;