介绍
本文章介绍了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;