Delphi中的操作二进制文件的两个重要函数
2016-01-19 17:13
459 查看
Delphi中的操作二进制文件的两个重要函数
对于通过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;
相关文章推荐
- Delphi出现“borland license information was found,but it is not valid for delphi”的错误,无法运行的解决方法
- FastReport 动态加载图片
- delphi:斑马打印机ZPL指令打印中文及二维码
- Delphi下使用Sato打印机
- Delphi ListView基本用法大全
- Delphi禁止重复运行同一程序的方法
- 多级接口实现方法
- Panel移动
- Delphi获取句柄并发送消息
- delphi 获取文件所在路径
- 使用delphi+intraweb进行微信开发1--微信平台接入
- 使用delphi+intraweb进行微信开发1--微信平台接入
- Delphi 类方法的搞笑答案
- Delphi 全面控制Windows任务栏
- Delphi IOS 后台定时器
- 【转】Delphi+Halcon实战一:两行代码识别QR二维码
- Delphi字符串加密/解密
- delphi操作xml学习笔记 之一 入门必读
- Delphi接口使用实例介绍
- Delphi Math单元函数