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

你可能感兴趣的:(Delphi I/O error 103 错误)