PB中读写⽂件通⽤的两个函数1、⽂件读取 :
//函数名:f_readfile
//功能:读取⽂件
//参数:
//  io_file:ref blob ⼤对象类型,存储读出的⽂件内容;
//  is_filename:string ⽂件名
//返回值:int  1-成功 0-失败
LONG ll_len
int li_FileNum,li_count,loops,i,bytes_read
blob lblb_b,tot_b
int liResult=1
ll_len=FileLength(is_filename)
IF ll_len > 32765 THEN
IF Mod(ll_len, 32765) = 0 THEN
loops = ll_len/32765
ELSE
loops = (ll_len/32765) + 1
END IF
ELSE
loops = 1
END IF
li_FileNum =  FileOpen(is_filename,StreamMode!, read!, lockread!)
if li_filenum = -1 then
messagebox("","⽆法打开⽂件"+ is_filename)
end if
FOR i = 1 to loops
bytes_read=FileRead(li_FileNum, lblb_b)
if bytes_read = -1 then
messagebox("","读取⽂件"+is_filename+"失败!")
liResult = 0
exit
end if
if i=1 then
tot_b = lblb_b
else
tot_b = tot_b + lblb_b
end if
NEXT
Fileclose(li_FileNum)
if liResult = 1 then
ib_file=tot_b
end if
return liResult
2、⽂件写⼊ :
/
/函数名:f_writefile
//功能:写⼊⽂件
//参数:
//  io_file:blob  ⼤对象类型,存储将写⼊的⽂件内容;
//  is_filename:string  ⽂件名
//返回值:int  1-成功 0-失败
uLONG ll_len,li_count,loops
int li_FileNum
blob lblb_b
int liResult = 1
ll_len=len(ib_file)
IF ll_len > 32765 THEN
IF Mod(ll_len, 32765) = 0 THEN
loops = ll_len/32765
ELSE
loops = (ll_len/32765) + 1
END IF
ELSE
loops = 1
END IF
li_FileNum =  FileOpen(is_filename,StreamMode!, write!, shared!,Replace!) if li_FileNum = -1 then
messagebox("系统提⽰","⽆法打开⽂件"+is_filename)
return 0
end if
FOR li_count = 1 to loops
lblb_b = blobmid( ib_file , ( li_count - 1) * 32765 + 1 , 32765 )
if FileWrite(li_FileNum, lblb_b) = -1 then
messagebox("系统提⽰","写⽂件" + is_filename+"失败")
liResult=0
exit
end if//8010
NEXT
Fileclose(li_FileNum)write的返回值
/
/if liResult=1 then
// liResult = gf_setfiletime(is_filename,idt_file_time)
//end if

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。