Delphi I/O error 103 错误

http://stackoverflow.com/questions/634587/delphi-why-do-i-sometimes-get-an-i-o-error-103-with-this-code

I don't see what is wrong with automatic retry. I don't see that you can do anything else.

 

If some other process is reading the file, then your Append/Rewrite will fail.

假如某个其他进程正在读取这个问题,这时你做Append Rewite 操作的话就会出错。

 

And since the file is a log, there is a good chance that something, such as a log viewer or a text editor, will be reading it at the instant you try to open it.

Try opening the file a few times with a delay in-between attempts before failing definitively.

在明确失败前,试试打开以一定的间隔打开这个文件几次。

You could use an exponential backoff if you wanted to be fancy.

你可以用一个变量控制。

 

try
   ReWrite(MyFileHandler); // This sometimes fails except ReWrite(MyFileHandler); // When prior fails, this runs OK end;

用户环境:

使用该软件已经快8年了,最近安装了360卫士和杀毒。

保存时提示该错误。

其他:

http://stackoverflow.com/questions/22026948/how-do-i-solve-i-o-error-103-in-delphi

http://stackoverflow.com/questions/16287983/why-do-i-get-i-o-error-32-even-though-the-file-isnt-open-in-any-other-program

http://mc-computing.com/languages/delphi/delphifileio.htm

 

测试:

procedure TForm1.Button1Click(Sender: TObject);
var
F,n: TextFile;
const
filestr = 's:\test.txt';
begin
AssignFile(f, filestr);
Append(f);// 不存在这个文件时,报File not found;存在时 无报错。
end
procedure TForm1.Button1Click(Sender: TObject);
var
  F,n: TextFile;
const
  filestr = 's:\test.txt';
begin
//  AssignFile(f, filestr);//无这行 报I/O error 102
  Append(f);
//  Rewrite(f);
//  Writeln(f, 'abcs:\');
//  CloseFile(f);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  F,n: TextFile;
const
  filestr = 's:\test.txt';
begin
  AssignFile(f, filestr);//无这行 报I/O error 102
  Append(f);
  Append(f);//第二次时点击按钮时 报 I/O error 32 资源管理器里删除该文件的话,提示 已经被其他程序打开

end;
procedure TForm1.Button1Click(Sender: TObject);
var
  F,n: TextFile;
const
  filestr = 's:\test.txt';
begin
  AssignFile(f, filestr);
//  Append(f);//无这行,报 I/O error 103
  CloseFile(f);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  F,n: TextFile;
const
  filestr = 's:\test.txt';
begin
  AssignFile(f, filestr);
  Append(f);

  Writeln(f, 'abcs:\');
  CloseFile(n);//n变量 未关联文件时,报103
end;

 

 

可能的原因:

1、Append时,

 

转载于:https://www.cnblogs.com/CodeGear/p/4143395.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值