全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1411
推到 Plurk!
推到 Facebook!

檔案大小問題

尚未結案
kamiche
一般會員


發表:5
回覆:5
積分:2
註冊:2003-04-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-24 17:59:19 IP:61.231.xxx.xxx 未訂閱
各位大大,小弟有個問題想請教,就是從檔案內容看檔案大小時,明明寫大小 34.0 KB (34,820 位元組),為甚麼從ULTRAEDIT看卻有位置標示居然有34855的大小,小弟不才就用下列方式將A檔案讀出再寫入B檔案,居然後面最後面還是有不一樣,請教這是哪邊出問題?      assignfile(Afile,fAname);   Reset(Afile,1);   assignfile(Bfile,fBname);   Rewrite(Bfile,1);   while Not Eof(Afile) do   Begin    Blockread(afile, a, 1);    BlockWrite(Bfile, a, sizeof(a) );   End;   Closefile(bfile);   Closefile(afile);    A檔案: http://home.pchome.com.tw/cool/kamichen/A.BMD PS:PCHOME在檔案最前面有加了一些東西,所以檔案大小變了
tonytop
中階會員


發表:6
回覆:114
積分:89
註冊:2003-12-04

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-24 18:11:32 IP:210.64.xxx.xxx 未訂閱
這只是bytes換算 K bytes後的問題而已吧! 34820/1024 = 34.00390625 K 取到小數點後一位成為34.0 K
kamiche
一般會員


發表:5
回覆:5
積分:2
註冊:2003-04-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-24 19:13:20 IP:61.231.xxx.xxx 未訂閱
感謝,可是好像不是這樣也
tonytop
中階會員


發表:6
回覆:114
積分:89
註冊:2003-12-04

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-25 09:36:39 IP:210.64.xxx.xxx 未訂閱
天才,您的指令下錯了,我用delphi的範例改成下列程式,copy出 來的檔案和原來的一模一樣,最後面沒有多東東,另外您沒有移動 檔案指標,用Eof(Afile)會跑不完,成為無窮迴圈喔!  
var
  Afile, Bfile:File;
  a:array[1..2048] of Char;
  NumRead, NumWritten:Integer;
  fAname, fBname:String;
begin
  fAname:='c:\A.BMD';
  fBname:='c:\B.BMD';      assignfile(Afile, fAname);
  Reset(Afile, 1);      assignfile(Bfile, fBname);
  Rewrite(Bfile, 1);
  repeat
    Blockread(afile, a, SizeOf(a), NumRead);
    BlockWrite(Bfile, a, NumRead, NumWritten);
  until (NumRead=0)or(NumWritten<>NumRead);      Closefile(bfile);
  Closefile(afile);
 
kamiche
一般會員


發表:5
回覆:5
積分:2
註冊:2003-04-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-11-28 18:47:57 IP:61.231.xxx.xxx 未訂閱
感謝tonytop大大,另外一個問題就是我把a變數宣告成BYTE後寫到B檔案就會發生我說的問題,但是a變數宣告成char就沒這樣的問題 可以在幫我嗎?感恩喔
tonytop
中階會員


發表:6
回覆:114
積分:89
註冊:2003-12-04

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-11-29 13:19:34 IP:210.64.xxx.xxx 未訂閱
我剛試把a變數宣告成BYTE後寫到B檔案,用ULTRAEDIT的「比較檔案」功能, 得到的結果還是一模一樣耶,是否你有部份作法造成不同呢?    
 
procedure TForm1.Button2Click(Sender: TObject);
var
  Afile, Bfile:File;
  a:array[1..2048] of Byte; //////  
  NumRead, NumWritten:Integer;
  fAname, fBname:String;
begin
  fAname:='c:\A.BMD';
  fBname:='c:\B.BMD';      assignfile(Afile, fAname);
  Reset(Afile, 1);      assignfile(Bfile, fBname);
  Rewrite(Bfile, 1);
  repeat
    Blockread(afile, a, SizeOf(a), NumRead);
    BlockWrite(Bfile, a, NumRead, NumWritten);
  until (NumRead=0)or(NumWritten<>NumRead);      Closefile(bfile);
  Closefile(afile);
end;
我正確的mail:h832214@hotmail.com
kamiche
一般會員


發表:5
回覆:5
積分:2
註冊:2003-04-06

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-11-29 17:31:05 IP:61.231.xxx.xxx 未訂閱
tonytop 大大,我把我的程式寄給你,你試試看
系統時間:2024-05-15 3:17:47
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!