Delphi中的操作二进制文件的两个重要函数
2010-09-28 10:58
232 查看
对于通过Byte数组进行文件操作的,在FTP中经常会使用到,我也是在Delphi调用Web Service进行文件的上传和下载时找到这两个函数的,挺好用的,推荐给大家。(申明:非本人所写)
1. 将Byte数组生成文件
procedure ByteArrayToFile(const ByteArray : TByteDynArray; const FileName : string );
var
Count: integer;
F: FIle of Byte;
pTemp: Pointer;
begin
AssignFile( F, FileName );
Rewrite(F);
try
Count := Length( ByteArray );
pTemp := @ByteArray[0];
BlockWrite(F, pTemp^, Count );
finally
CloseFile( F );
end;
end;
2. 将文件生成Byte数组
function FiIeToByteArray(const FileName:string ):TByteDynArray;
const
BLOCK_SIZE=1024;
var
BytesRead,BytesToWrite,Count:integer;
F:File of Byte;
pTemp:Pointer;
begin
AssignFile( F, FileName );
Reset(F);
try
Count := FileSize( F );
SetLength(Result, Count );
pTemp := @Result[0];
BytesRead := BLOCK_SIZE;
while (BytesRead = BLOCK_SIZE ) do
begin
BytesToWrite := Min(Count, BLOCK_SIZE);
BlockRead(F, pTemp^, BytesToWrite , BytesRead );
pTemp := Pointer(LongInt(pTemp) BLOCK_SIZE);
Count := Count-BytesRead;
end;
finally
CloseFile( F );
end;
end;
1. 将Byte数组生成文件
procedure ByteArrayToFile(const ByteArray : TByteDynArray; const FileName : string );
var
Count: integer;
F: FIle of Byte;
pTemp: Pointer;
begin
AssignFile( F, FileName );
Rewrite(F);
try
Count := Length( ByteArray );
pTemp := @ByteArray[0];
BlockWrite(F, pTemp^, Count );
finally
CloseFile( F );
end;
end;
2. 将文件生成Byte数组
function FiIeToByteArray(const FileName:string ):TByteDynArray;
const
BLOCK_SIZE=1024;
var
BytesRead,BytesToWrite,Count:integer;
F:File of Byte;
pTemp:Pointer;
begin
AssignFile( F, FileName );
Reset(F);
try
Count := FileSize( F );
SetLength(Result, Count );
pTemp := @Result[0];
BytesRead := BLOCK_SIZE;
while (BytesRead = BLOCK_SIZE ) do
begin
BytesToWrite := Min(Count, BLOCK_SIZE);
BlockRead(F, pTemp^, BytesToWrite , BytesRead );
pTemp := Pointer(LongInt(pTemp) BLOCK_SIZE);
Count := Count-BytesRead;
end;
finally
CloseFile( F );
end;
end;
相关文章推荐
- Delphi中的操作二进制文件的两个重要函数
- Delphi中的操作二进制文件的两个重要函数
- Delphi中的操作二进制文件的两个重要函数
- Delphi中的操作二进制文件的两个重要函数
- Delphi中的操作二进制文件的两个重要函数
- [C语言] 文件操作,对二进制文件追加二进制数据与补零的两个函数;
- 两个delphi下遍历指定目录下指定类型文件的函数
- Delphi文件操作函数
- Delphi文件操作所涉及的一些函数
- PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用
- Delphi文件操作函数
- Delphi文件操作函数
- Delphi文件操作所涉及的一些函数 附例子
- [C语言] 文件操作,合并两个二进制文件为单独一个二进制文件;
- Delphi文件操作所涉及的一些函数
- Delphi文件操作所涉及的一些函数
- Delphi 文件、目录等常用操作函数 - delphi - gliethttp
- Delphi文件操作函数
- Delphi文件操作所涉及的一些函数
- Delphi文件操作常用函数