Delphi – 以只读方式打开zipfile
发布时间:2020-12-15 09:23:24 所属栏目:大数据 来源:网络整理
导读:我使用内部TZipFile. 当我打开拉链时,德尔福似乎只打开它. 只要未释放zipfile,就会拒绝文件访问 lZipFile := tZipFile.Create;if lZipFile.IsValid( sPath) then begin lZipFile.Open( sPath,zmRead );...// access denied to sPathend;lZipFile.Free; 我只
我使用内部TZipFile.
当我打开拉链时,德尔福似乎只打开它. 只要未释放zipfile,就会拒绝文件访问 lZipFile := tZipFile.Create; if lZipFile.IsValid( sPath) then begin lZipFile.Open( sPath,zmRead ); ... // access denied to sPath end; lZipFile.Free; 我只想读.为什么delphi表现得那样? 知道我可以做什么来同时以只读模式访问同一个zip吗? 解决方法
您可以创建使用所需共享模式打开的TFileStream实例.然后使用接受TStream的TZipFile的重载Open方法.
请注意,TZipFile.IsValid也会尝试独占打开该文件.由于IsValid没有做Open也做的事情,我添加了一个try-except块来捕获任何无效或无法访问的目标.因此可以省略对IsValid的调用. zip := TZipFile.Create; try stream := TFileStream.Create(sPath,fmOpenRead + fmShareDenyWrite); try try zip.Open(stream,zmRead); except on EZipException do begin // access denied to sPath end; end; finally stream.Free; end; finally zip.Free; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |