当前位置: 首页 > 工具软件 > Lunzip > 使用案例 >

delphi 压缩和解压文件

荆钱明
2023-12-01

需要引入system.ZLib包

procedure TFormMain1.Button25Click(Sender: TObject);   //压缩
var
  LInput, LOutput: TFileStream;
  LZip: TZCompressionStream;
begin
  inherited;
  LInput := TFileStream.Create(Edit2.Text, fmOpenRead);   //需要压缩的文件
  LOutput := TFileStream.Create(Edit3.Text + '.zip', fmCreate);  //压缩完成的文件
  LZip := TZCompressionStream.Create(LOutput);

  LZip.CopyFrom(LInput, LInput.Size);

  LZip.Free;
  LInput.Free;
  LOutput.Free;

end;

procedure TFormMain1.Button26Click(Sender: TObject);   //解压
var
  LInput, LOutput: TFileStream;
  LUnZip: TZDecompressionStream;

begin
  { Create the Input, Output, and Decompressed streams. }
  LInput := TFileStream.Create(Edit2.Text, fmOpenRead);  //解压的文件
  LOutput := TFileStream.Create(ChangeFileExt(Edit3.Text, '.txt'), fmCreate);  //解压后的文件
  LUnZip := TZDecompressionStream.Create(LInput);

  { Decompress data. }
  LOutput.CopyFrom(LUnZip, 0);

  { Free the streams. }
  LUnZip.Free;
  LInput.Free;
  LOutput.Free;
end;

 

转载于:https://www.cnblogs.com/yangxuming/p/11429534.html

 类似资料: