本文整理自网络,侵删。
介绍
本文章介绍了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 多核机器上编程实现将指定进程pid放到指定cpu上运行
Delphi try except语句 和 try finally语句用法以及区别
Delphi xe 7 mediaplayer 在安卓里放不出声音
更多相关阅读请进入《Delphi》频道 >>