PB读和写大于32K(32765B)数据
string export_filepath,export_filename
string gs_importfilepath,gs_importfilename
//读取大文本数据
if GetFileOpenName("选择要导入的文件", gs_importfilepath,gs_importfilename, "dat", &
+ "Dat Files (*.dat),*.dat," + "TEXT Files (*.txt),*.txt," +"All Files (*.*), *.*", gs_filepath, 18)()<>1 then return
long ll_FLength,ll_FileNum
string ls_filecontext,ls_tmp
int i,loops,j
debugbreak()
ll_FLength = filelength(gs_importfilepath)
ll_FileNum = FileOpen(gs_importfilepath,StreamMode!, Read!, LockWrite!, Replace!)
if ll_FLength > 32765 then
if mod(ll_FLength,32765) = 0 then
loops= ll_FLength/32765
else
loops= ll_FLength/32765 +1
end if
else
loops=1
end if
// read file
SetPointer(hourglass!)
for i=1 to loops
j=FileRead(ll_filenum,ls_tmp)
ls_filecontext=ls_filecontext + ls_tmp
next
FileClose(ll_FileNum)
mle_1.text=ls_filecontext
//写大文本数据
if Getfilesavename("选择保存路径",export_filepath,export_filename,&
"dat","DAT Files (*.dat),*.dat,"+ "TEXT Files (*.txt),*.txt,"+"ALL Files (*.*),*.*",gs_filepath,32770)<>1 then return
long ll_FLength,ll_FileNum
string ls_filecontext,ls_tmp
int i,loops,j
boolean lb_delete
debugbreak()
ls_filecontext=mle_1.text
ll_FLength = len(ls_filecontext)
ll_FileNum = FileOpen(export_filepath,StreamMode!, Write!, LockWrite!, Append!) //以追加的方式,打开选择的保存路径
if export_filepath=gs_importfilepath then //如果是以前的老文件,就把原来的文件删除.
FileClose(ll_FileNum)
lb_delete=filedelete(gs_importfilepath)
ll_FileNum = FileOpen(export_filepath,StreamMode!, Write!, LockWrite!, Append!)
end if
if ll_FLength > 32765 then
if mod(ll_FLength,32765) = 0 then
loops= ll_FLength/32765
else
loops= ll_FLength/32765 +1
end if
else
loops=1
end if
// write file //每次向文件中写32765个字节,分多次写
for i=1 to loops
ls_tmp=left(ls_filecontext,32765)
FileWrite(ll_FileNum,ls_tmp)
ls_filecontext=right(ls_filecontext,len(ls_filecontext) - 32765)
next
FileClose(ll_FileNum)