pb 打开文件,写入文件

 打开文件

global type gf_readfile from function_object
end type

forward prototypes
global function blob gf_readfile (string as_path, string as_file)
end prototypes

global function blob gf_readfile (string as_path, string as_file);integer li_FileNum, loops, i//wxk20110214
long flen, bytes_read, new_pos
blob b, tot_b
//得到当前选择的文件的内容大小,sle_filename包含文件所在路径及文件名
flen = FileLength(as_path)
//打开文件
li_FileNum = FileOpen(as_path,StreamMode!, Read!, LockRead!)
//由于FileRead函数一次只能读出32765大小的数据,所以先计算读取次数
IF flen > 32765 THEN
	IF Mod(flen, 32765) = 0 THEN
		loops = flen/32765
	ELSE
		loops = (flen/32765) + 1
	END IF
ELSE
	loops = 1
END IF
new_pos = 1
//分多次读出文件中的所有数据,放在tot_b变量中
FOR i = 1 to loops
bytes_read = FileRead(li_FileNum, b)
tot_b = tot_b + b
NEXT
//关闭文件
FileClose(li_FileNum)
return tot_b

end function

写入文件

global type gf_writefile from function_object
end type

forward prototypes
global function integer gf_writefile (string as_file_name, blob ab_to_write)
end prototypes

global function integer gf_writefile (string as_file_name, blob ab_to_write);integer li_FileNum, loops, i

long flen, bytes_read//, new_pos

blob b

flen = len(ab_to_write)

li_FileNum = FileOpen(as_file_name,StreamMode!, write!,LockReadWrite!,Replace! )

if li_filenum < 0 then
//	if not this.del(as_file_name) then
//		return -1
//	else
		li_FileNum = FileOpen(as_file_name,StreamMode!, write!,LockReadWrite!,Replace! )
		if li_filenum < 0 then
			return -2
		end if
//	end if
end if
IF flen > 32765 THEN
	IF Mod(flen, 32765) = 0 THEN
		loops = flen/32765
	ELSE
		loops = (flen/32765) + 1
	END IF
ELSE
	loops = 1
END IF
//new_pos = 1

FOR i = 1 to loops
	filewrite(li_filenum,blobmid(ab_to_write,32765 * (i - 1) + 1,32765 ))
NEXT

FileClose(li_FileNum)
return 1
end function

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值