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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM