Assignfile(hfile,'f:\wp.txt'); try if fileexists('f:\wp.txt') then append(hfile) else rewrite(hfile); finally closefile (hfile); end;
程序肯定没问题,是不是系统有问题,我加了TRY也不行, 还有:F:\是有操作权限的.
这一段代码你是不是执行了2次以上?(我想一定是的) Assignfile(hfile,'f:\wp.txt'); if fileexists('f:\wp.txt') then append(hfile) else rewrite(hfile); 第一遍Append函数使文件进入添加模式,然后你在没有关闭文件的情况下又调用 Append,是不是?所以就出错了。记得该关闭时一定要关闭文件!! ------------------------------------------------------------------------ superyiman(役满)的代码时正确的
FileName:='f:\wp.txt';if FileExists(FileName) then Begin Assignfile(hfile,FileName); Append(HFile);//Call Append to ensure that a file is opened with write-only //access with the file pointer positioned at the end of //the file. Writeln(HFile, 'appended text'); ... CloseFile(HFile); //Close file, save changes End else Begin Assignfile(hfile,FileName); FileMode:=1;// write only ReWrite(HFile); Writeln(HFile, 'appended text'); ... CloseFile(HFile); //Close file, save changes End; if fileexists('f:\wp.txt') then else rewrite(hfile); 为什么一执行到 Append 句 或 Rewrite 句,就会出错 I/O 32
try
if fileexists('f:\wp.txt') then
append(hfile)
else
rewrite(hfile);
finally
closefile (hfile);
end;
还有:F:\是有操作权限的.
Assignfile(hfile,'f:\wp.txt');
if fileexists('f:\wp.txt') then
append(hfile)
else
rewrite(hfile);
第一遍Append函数使文件进入添加模式,然后你在没有关闭文件的情况下又调用
Append,是不是?所以就出错了。记得该关闭时一定要关闭文件!!
------------------------------------------------------------------------
superyiman(役满)的代码时正确的
Begin
Assignfile(hfile,FileName);
Append(HFile);//Call Append to ensure that a file is opened with write-only
//access with the file pointer positioned at the end of
//the file.
Writeln(HFile, 'appended text');
...
CloseFile(HFile); //Close file, save changes
End
else
Begin
Assignfile(hfile,FileName);
FileMode:=1;// write only
ReWrite(HFile);
Writeln(HFile, 'appended text');
...
CloseFile(HFile); //Close file, save changes
End;
if fileexists('f:\wp.txt') then
else
rewrite(hfile);
为什么一执行到 Append 句 或 Rewrite 句,就会出错 I/O 32
所以把你程序中HFILE都改为myfile就正常了
要是还有问题,请把你的程序发到[email protected],我好好帮你看看.
if not FileExists(filename) then
rewrite(fp)
else
reset(fp);//呵呵,你只记得rewrite,却忘了reset
append(fp);