• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

DelphiI/Oerror103错误

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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时,

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi中共享内存学习发布时间:2022-07-18
下一篇:
Delphi日期函数(Day、Mon、Year、Week)使用方法发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap