详解ReWrite, BlockWrite, BlockRead 的用法

Rewrite函数:

Delphi syntax:

procedure Rewrite(var F: File [; Recsize: Word ] );

功能说明:以可写方式打开文件。如果文件不存在,将会自动创建。使用该函数,将会覆盖文件中的所有内容。

说明:在DELPHI代码中,Rewrite将用关联的文件F创建一个新文件。F是一个可变的任意类型文件,通常用AssignFile去关联一个外部的文件。

Recsize是一个可选的表达式,它仅仅指定于无类型文件(即无类型文件必须指定Recsize的大小)。如果F是一个无类型文件, 通常在文件读写中RecSize指定记录的大小。如果RecSize没有指定大小,将会采用一个默认的大小128字节。

 如果一个同名的外部文件已经存在,那么它先被删除然后创建一个新的空的文件去代替它。

如果文件已经被打开,那么首先先关闭它然后再重新创建。文件指针指向空文件的开始。

如果F关联到一个空文件名,例如AssignFile(F,''),当引用Rewrite后,F将会关联到一个标准的文件(F refers to the standard output file).

如果F是一个文本文件,F将变成write-only.

当使用Rewrite, 文件指针将指向最后,取出EOF(F)是真的。

 

procedure BlockRead(var F: File; var Buf; Count: Integer [; var AmtTransferred: Integer]);

功能说明:

F是一无类型文件,Buf是任意类型变量,Count是整型表达式,AmtTransferred是可选整型表达式。

BlockRead从文件F读取Count或小于Count个记录到内存中,读取记录将存放到Buf中。实际读取的记录数存放到AmtTransferred中.

The entire transferred block occupies at most Count * RecSize bytes. RecSize is the record size specified when the file was opened (or 128 if the record size was not specified).

If the entire block was transferred, AmtTransferred is equal to Count.

If AmtTransferred is less than Count, ReadBlock reached the end of the file before the transfer was complete. If the file's record size is greater than 1, AmtTransferred returns the number of complete records read.

If AmtTransferred isn't specified, an I/O error occurs if the number of records read isn't equal to Count. If the $I+ compiler directive is in effect, errors raise an EInOutError exception.

 

 

procedure BlockWrite(var f: File; var Buf; Count: Integer [; var AmtTransferred: Integer]);

Description

F is an untyped file variable, Buf is any variable, Count is an expression of type Integer, and AmtTransferred is an optional variable of type Integer.

BlockWrite writes Count or fewer records to the file F from memory, starting at the first byte occupied by Buf. The actual number of complete records written (less than or equal to Count) is returned in AmtTransferred.

The entire block transferred occupies at most Count * RecSize bytes. RecSize is the record size specified when the file was opened (or 128 if the record size was unspecified).

If the entire block is transferred, AmtTransferred is equal to Count on return.

If AmtTransferred is less than Count, the disk became full before the transfer was complete. In this case, if the file's record size is greater than 1, AmtTransferred returns the number of complete records written.

BlockWrite advances the current file position by AmtTransferred records.

If AmtTransferred isn't specified, an I/O error occurs if the number written isn't equal to Count. If the $I+ compiler directive is in effect, errors raise an EInOutError exception.

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值