[PB] PB中读写文件通用的两个函数
来源:互联网 发布:xy烈咬陆鲨mega数据 编辑:程序博客网 时间:2024/05/17 06:10
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)
//if liResult=1 then
// liResult = gf_setfiletime(is_filename,idt_file_time)
//end if
return liResult
- [PB] PB中读写文件通用的两个函数
- pb中截取小数位的两个函数
- PB中对INI文件读写的补充函数:删除指定的节或者指定节中某个项
- 【PB】在PB中动态调用函数
- pb中函数大全
- PB通用的编程规范
- PB通用的编程规范
- PB中数据窗口的函数小结
- Pb中Yield()函数的使用
- PB中数据窗口的函数小结
- PB学习中遇到的函数
- pb中数据窗口的部分函数
- pb的opensheet函数
- PB函数的调用
- pb的find函数
- pb文件的使用
- pb中如何算两个日期的时间间隔
- PB中 autocommit 和 commitondisconnect 两个连接参数的应用
- C指针(转)
- C# 数据库连接字符串集合
- 优化Oracle库表设计的若干方法
- httpclient
- 内华达如何发展经济?
- [PB] PB中读写文件通用的两个函数
- WINCE 注册表自举
- ctags使用简介(linux下的代码管理工具)
- 今天开通了CSDN的博客!
- struts2表单验证及国际化实现
- afaca 分析报告
- 多条重复记录取一条
- 坤和中心(http://www.canhighcenter.com/)
- vba dictionray