文件是否可以同时被多个文件流使用? ( 积分: 100 )

  • 主题发起人 主题发起人 zyyjc
  • 开始时间 开始时间
Z

zyyjc

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在通过HTTP下载文件,
在下载的过程中想访问这个文件,我是这样做的:
desFile := TFileStream.Create(sFileName, fmOpenRead);
可是提示“另一程序正在使用此文件,进程无法访问”
请问有什么办法可以解决这个问题?
 
原始办法:用程序将此文件COPY一份出来,再打开COPY出的这一份。
 
应该可以,只要不设置为独占模式就行
 
如果 http下载使用了独占方式,其他文件流是不能打开的,否则可以用
tfilestream.create(sfile, fmopenread+fmdenynone) 打开
 
文件打开方式的问题
Value Meaning

fmCreate Create a file with the given name. If a file with the given name exists, open the file in write mode.
fmOpenRead Open the file for reading only.
fmOpenWrite Open the file for writing only. Writing to the file completely replaces the current contents.
fmOpenReadWrite Open the file to modify the current contents rather than replace them.

The share mode must be one of the following values:

Value Meaning

fmShareCompat Sharing is compatible with the way FCBs are opened.
fmShareExclusive Other applications can not open the file for any reason.
fmShareDenyWrite Other applications can open the file for reading but not for writing.
fmShareDenyRead Other applications can open the file for writing but not for reading.
fmShareDenyNone No attempt is made to prevent other applications from reading from or writing to the file.


fm
 
HTTP下载方式:
TFileStream.Create(FileNameEdit.Text, fmcreate);
这个语句是不是独占的,有什么办法能设为不是独占的方式??
 
var
iFile: Integer;
begin
iFile := FileOpen(sFile, fmOpenRead or fmShareDenyNone);
// 在这里对 iFile 进行(FileRead)等操作就行了
end;
 
后退
顶部