Delphi XE5在Zip文件中添加某个Txt文件并写入文字


本文整理自网络,侵删。

 介绍

本文章介绍了Delphi XE5在Zip文件中添加某个Txt文件并写入文字,首先我们定义一个Zip文件,并通过ZipFile组件打开这个ZIP文件,然后操作TStringStream对象,将字符串写入到TStringStream里面,并写入到ZIP文件中,下面是具体代码


procedure TForm1.Button1Click(Sender: TObject);

var

  ZipFile: TZipFile;

  SS: TStringStream;

const

ZipDocument = 'd:\temp.zip';

begin

  ZipFile := TZipFile.Create; //Zipfile: TZipFile

  SS := TStringStream.Create('hello');

  try

    if FileExists(ZipDocument) then

      ZipFile.Open(ZipDocument, zmReadWrite)

    else

      ZipFile.Open(ZipDocument, zmWrite);


    ZipFile.Add(SS, 'document.txt');


    ZipFile.Close;

  finally

    SS.Free;

    ZipFile.Free;

  end;

end;

相关阅读 >>

Delphi比较两个位图是否相同

Delphi取代sleep的延时代码

Delphi 实现打开文件定位

Delphi中将webbrowser用作网页编辑器

Delphi使用idhttp模拟提交页面方法总结

Delphi 多核机器上编程实现将指定进程pid放到指定cpu上运行

Delphi try except语句 和 try finally语句用法以及区别

Delphi xe 7 mediaplayer 在安卓里放不出声音

Delphi 数据库获取所有用户名

Delphi 对zlib单元进行再封装

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...