線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3551
推到 Plurk!
推到 Facebook!

Writeln時的I/O error 105

尚未結案
alice
初階會員


發表:41
回覆:49
積分:28
註冊:2002-04-30

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-28 16:09:35 IP:211.75.xxx.xxx 未訂閱
打算讀一text file,若第一碼是空白,則填入'B'值,再寫回text file, 可是要Writeln時,會出現 I/O error 105 的錯誤訊息,    為什麼?    寫法如下: var FileName:string;     F1:TextFile;     sLine: string;     sLenght:integer; begin   FileName:='\\SERVER\TEMP\TEST.TXT';   AssignFile(F1, FileName);   try     Reset(F1);     while not Eof(F1) do begin       ReadLn(F1, sLine);       sLenght:=Length(sLine);       if copy(sLine,1,1)=' ' then begin          sLine:='B'+copy(sLine,2,sLenght-1);          Writeln(sLine);       end;     end;   finally     CloseFile(F1);   end; end;
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-28 16:30:31 IP:147.8.xxx.xxx 未訂閱
Reset is for read only access, you need to use Rewrite for writing. In your case I suggest using TFileStream or BlockRead/BlockWrite since rewrite will make a file write only.
alice
初階會員


發表:41
回覆:49
積分:28
註冊:2002-04-30

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-28 16:58:57 IP:211.75.xxx.xxx 未訂閱
若將Reset 改為ReWirte 時,不就重建了\\SERVER\TEMP\TEST.TXT 反而變成空檔了, 有去查了一下,BlockRead/BlockWrite , 發現是不是要來源檔及目的檔兩個檔案作業, 不能直接在同一檔案做修改,    致於TFileStream 好像沒有提供直接可讀取一行的資料, 因為我希望可以,一次讀一行資料,因為我還要去拆解資料,做處理.  有沒有TFileStream 的範例??
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-05-28 17:17:25 IP:147.8.xxx.xxx 未訂閱
BlockRead and BlockWrite can be used on the same file. Although it is the faster way to read/write a file, it is more difficult to use compared with file stream. If your file is small enough, could it be easier to load the whole file into a TStringList and then do you replacement and write it back later?    For a file stream, e.g.
var
    f: TFileStream;
    c: char;
{....}
f := TFileStream.Create('xxx.txt');
try
    while f.Position < f.Size do begin
        f.Read(c,SizeOf(c));
        if c=' ' then begin    
            f.Seek(-SizeOf(c),soFromCurrent);
            c := 'B';
            f.Write(c,SizeOf(c));
        end;
    end;
finally
    f.Free;
end;
Of course this is not what you want since there is no checking of line break. It is just an example (not tested ).
懷舊的人
高階會員


發表:28
回覆:152
積分:141
註冊:2003-01-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-05-28 20:16:03 IP:152.104.xxx.xxx 未訂閱
我會建議妳使用 1. TRichEdit(PlainText = True) RichEdit1.Lines.LoadFromFile(text file name); 取得第一行資料 S := RichEdit1.Lines[0]; 取得第五行資料 S := RichEdit1.Lines[4]; 2. TMemo (win 2000 可 > 64k) Memo1.Lines.LoadFromFile(text file name); 取得第一行資料 S := Memo1.Lines[0]; 取得第五行資料 S := Memo1.Lines[4]; 3. 使用 TStringList var I: Integer; S: String; SL: TStringList; begin SL := TStringList.Create; try SL.LoadFromFile(text file name); for I := 0 to SL.Count-1 do begin S := SL.Strings[I]; // 取得一行資料 // 處理過程 // 處理完畢 SL.Strings[I] := S; end; finally SL.SaveToFile(text file name); SL.Free; end;
系統時間:2024-05-20 8:47:42
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!