題目為:button1.Click創建一個E:\one.txt 文件, 然後往其中按順序加入'a', 'b', 'c'
也就是說: 不管button1  click多少次, one.txt中的內容始終為:
a
b
c===================================================================
我寫了如下, 不知道錯在哪了,它說:I/O error 32.  哪位高手能給我一個正確的完善的程序, 多謝了!
  FileCreate  ('E:\one.txt');
  AssignFile (f, 'E:\one.txt');
  append (f);
  writeln(f, 'a');
  writeln(f, 'b');
  writeln(f, 'c');

解决方案 »

  1.   

    var
      f: System.Text;
    begin
      AssignFile(f, 'c:\temp\one.txt');
      Rewrite(f);
      Writeln(f, 'a');
      Writeln(f, 'b');
      Writeln(f, 'c');
      CloseFile(f);
    end;
      

  2.   

    對不起, 我的代碼總體來講是這樣的,button1.Click中使用一個循環創建了幾十個文本文檔(1.txt, 2.txt,3.txt...),
    我是使用FileCreate  函數來創建的。
    然後button2.Click中再用一個循環往這些文本文檔中寫數據所以在我的系統中必須要先創建文本文檔,然後獲得局柄,再寫值,
    而不好每一個文件都先有局柄,再創建, 所以你給的方法我不好用. :)看看我的代碼:為什麼會有錯?
      FileCreate  ('E:\one.txt');
      AssignFile (f, 'E:\one.txt');
      append (f);
      writeln(f, 'a');
      writeln(f, 'b');
      writeln(f, 'c');
      

  3.   

    var
     f:TextFile;
    begin
      AssignFile (f, 'E:\one.txt');
      Rewrite(f);
      Writeln(f, 'a');
      Writeln(f, 'b');
      Writeln(f, 'c');
      CloseFile(f);
      

  4.   

    // 看这样可以不?~~ 注意:Flush、CloseFile都不能少~~
    var
      f: TextFile;
    begin
      FileClose(FileCreate('c:\temp\one.txt'));
      AssignFile(f, 'c:\temp\one.txt');
      Append(f);
      Writeln(f, 'a');
      Writeln(f, 'b');
      Writeln(f, 'c');
      Flush(f);
      CloseFile(f);
    end;
      

  5.   

    回复人: postfxj(探索者) ( ) 信誉:100 
    写的是正确的