对于通过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. Javascript初学篇章_7(DOM)
  2. {VS2010C#}{WinForm}{ActiveX}VS2010C#开发基于WinForm的ActiveX控件
  3. android Android-PullToRefresh 下拉刷新
  4. <转+改>Web测试中关于登录的测试
  5. JS 函数参数
  6. eclipse搭建Log4J日志环境
  7. scala akka 修炼之路5(scala特质应用场景分析)
  8. 【IE6的疯狂之十一】CSS的优先级及!important在IE6下的BUG
  9. [git] 细说commit (git add/commit/diff/rm/reset 以及 index 的概念)
  10. JSP EL表达式使用
  11. ios 添加工程依赖只能生成Generic Xcode Archive 文件原因
  12. kafka环境
  13. 转载:Allegro实用技巧之模块复用
  14. 小程序多端框架全面测评:chameleon、Taro、uni-app、mpvue、WePY
  15. SpringCloud之注册中心Eureka搭建
  16. 【第三篇】SAP ABAP7.5x新语法之程序结构&SubScreen
  17. JavaScript——封装
  18. json解析出来数据为空解决方法
  19. 【Spring】SpringMVC中浅析数据的传递方式
  20. Asp.net MVC 移除不用的视图引擎

热门文章

  1. Python list 列表和tuple元组
  2. 一个小笔记(5):A*算法
  3. jQuery筛选器及练习
  4. LeetCode 买卖股票的最佳时机
  5. 文件操作-mkdir
  6. Python操作微信跳一跳
  7. 继上次编译openwrt之后,添加web界面
  8. Python9-day4 作业
  9. Linux内核中的段属性
  10. 【实验吧】因缺思汀的绕过&&拐弯抹角&&Forms&&天网管理系统