知道一个文件的中HEAD的长度,如何去掉?比如head长(000H---aobH),如何去掉000H到
A0BH之间的内容,另存为一个文件?

解决方案 »

  1.   

    用二进制(即无类型文件)方式打开此文件,读取AOBH之后的整个文件内容,用它再存为一个新文件,OK!
      

  2.   

    是啊 既然知道了head的长度就可以只读取head之后的文件部分呀
      

  3.   

    定义两个数组(第二个可设为动态数组以针对不同大小的文件),打开文件后,用BLOCKREAD函数读取AOBH之前的内容到第一个数组中,读取AOBH之后的内容到第二数组中,再用BLOCKWRITE函数把第二数组内容写入一个新文件中即可。
      

  4.   

    对jhwh(弹剑长歌) 老兄进一言:
      
      你不该说那样的话。需知尺有所短,寸有所长。术业有专攻,个人针对的面也不一样,浩瀚未知,谁能穷尽?譬如我刚刚由一星变成二星,可我明白自己就只懂一丁点,象是TCP/IP协议及网络编程等等许许多多的东西至今都未涉及,一窍不通,对文件操作也只是刚刚做程序积累了一点点经验。愿我们都能善待他人,共同提高。共勉。
      

  5.   

    procedure TMainForm.btnCopyClick(Sender: TObject);
    var
      SrcFile, DestFile: File;
      BytesRead, BytesWritten, TotalRead: Integer;
      Buffer: array[1..500] of byte;
      FSize: Integer;
    begin
      { Assign both the source and destination files to their
        respective file variables }
      AssignFile(SrcFile, 'C:\graphinfo\tmp\edit.dwg');
      AssignFile(DestFile, 'C:\graphinfo\tmp\edit0.dwg');
      // Open the source file for read access.
      Reset(SrcFile, 1);
      try
        // Open destination file for write access.
        Rewrite(DestFile, 1);
        try
          { Encapsulate this into a try..except so that we can erase the file if
            an error occurs. }
          try
            // Initialize total bytes read to zero.
            TotalRead := 0;
            // Obtain the filesize of the source file
            //FSize := FileSize(SrcFile)-2571;
              FSize:=2571;
            { Read SizeOf(Buffer) bytes from the source file
              and add these bytes to the destination file. Repeat this
              process until all bytes have been read from the source
              file. A progress bar is provided to show the progress of the
              copy operation. }
            repeat
              BlockRead(SrcFile, Buffer, SizeOf(Buffer), BytesRead);
              if BytesRead > 0 then
              begin
                BlockWrite(DestFile, Buffer, BytesRead, BytesWritten);
                if BytesRead <> BytesWritten then
                  raise Exception.Create('Error copying file')
                else begin
                  TotalRead := TotalRead + BytesRead;
                  prbCopy.Position :=Trunc(TotalRead / Fsize) * 100;
                  prbCopy.Update;
                end;
              end
            until BytesRead = 0;
          except
            { On an exception, erase the destination file as it may be
              corrupt. Then re-raise the exception. }
            Erase(DestFile);
            raise;
          end;
        finally
          CloseFile(DestFile); // Close the destination file.
        end;
      finally
        CloseFile(SrcFile);   // Close the source file.
      end;
    end;
      

  6.   

    第一个BlockRead应该只读取AOBH之前的2571个字节数据,即改为:Buffer1: array[0..2570] of byte;
    Buffer2: array of byte;......
    SetLength(Buffer2,FSize); //设置Buffer2的长度BlockRead(SrcFile, Buffer1, SizeOf(Buffer1),BytesRead);  // 读取头2571个保留字节BlockRead(SrcFile, Buffer2, SizeOf(Buffer2),BytesRead); //再读取余下的所有字节数据:
    ......最后再用BlockWrite把Buffer2的内容写入一个新文件中即可。
      

  7.   

    修正一点:  SetLength(Buffer2,FSize); //设置Buffer2的长度
    改为:
      SetLength(Buffer2,FileSize(SrcFile)-2571); //设置Buffer2的长度
      

  8.   

    抱歉,还要补充一点:因为是操作动态数组,第二个BlockRead语句应改为:BlockRead(SrcFile, Buffer2[0], SizeOf(Buffer2),BytesRead); //再读取余下的所有字节数据你原来的方法大概是来自《DELPHI 5开发人员指南》上的例子,而上述方法因为是用两个BlockRead一次性完成文件读取操作,所以不必再用repeat循环。