Delphi中的操作二进制文件的两个重要函数
来源:互联网 发布:软件造价评估公司 编辑:程序博客网 时间:2024/06/08 05:27
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;
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;
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;
0 0
- Delphi中的操作二进制文件的两个重要函数
- Delphi中的操作二进制文件的两个重要函数
- Delphi中的操作二进制文件的两个重要函数
- Delphi线程中的两个重要概念
- Delphi两个有用的函数
- delphi 两个有意思的函数
- delphi 两个有意思的函数
- 判断文件是二进制文件还是文本文件的函数(VC,Delphi)
- 两个比较重要的js函数
- delphi中的字符串操作函数的使用(上)
- 文件操作,合并两个二进制文件为单独一个二进制文件
- Delphi读写XML的两个函数
- Delphi:两个高效的哈希函数
- Delphi操作Excel的重要属性及方法
- C#的二进制文件操作
- 对二进制文件的操作
- C++------二进制文件的操作
- 二进制文件的IO操作
- web.xml配置详解
- JBoss7.1配置Oracle11g数据源,详细图解
- Redis KVStore 在阿里云环境下的性能报告及问题
- [IOS 开发] 利用UIWebView 加载GIF动画
- 详解Spring Data JPA
- Delphi中的操作二进制文件的两个重要函数
- 一起做RGB-D SLAM (5)
- 杭电1048--输出输出格式控制
- SecureCrt连接Linux操作tomcat
- HTML文本编辑
- 【扣丁学堂】让程序员的开发项目不再半途而废
- jenkins调用webdriver
- 一起做RGB-D SLAM (6)
- 【爬虫之路】一点有关学习BeautifulSoup的笔记