读书人

怎么一行一行读取文本文件

发布时间: 2013-01-17 10:28:54 作者: rapoo

如何一行一行读取文本文件
请教各位高手 怎么样才能一行一行读文本文件
我下面的代码 只能显示一行 ,请问该怎么修改呢?谢谢
integer li_FileNum

string ls_Emp_Input

long ll_FLength

ll_FLength = FileLength("C:\fdff\acc.txt")

li_FileNum = FileOpen("C:\fdff\acc.txt", lineMode!)

IF ll_FLength < 32767 THEN

FileRead(li_FileNum, ls_Emp_Input)

messagebox('',ls_Emp_Input)

END IF


[解决办法]
你用的linemode就是固定读一行的,每次读一行,每次读完后文件指针就会移到行末,下次调用fileread就会接着读下一午,直到fileread返回-1就读完了
下面的代码是以streammode方式读取的,每次读取32765个字符
integer li_FileNum, loops, i

long flen, bytes_read, new_pos

blob b, tot_b

// Set a wait cursor

SetPointer(HourGlass!)

// Get the file length, and open the file

flen = FileLength(sle_filename.Text)

li_FileNum = FileOpen(sle_filename.Text, &

StreamMode!, Read!, LockRead!)

// Determine how many times to call FileRead

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

// Read the file

new_pos = 1

FOR i = 1 to loops

bytes_read = FileRead(li_FileNum, b)

tot_b = tot_b + b

NEXT

FileClose(li_FileNum)
[解决办法]
楼上为流模式...但写法一样
[解决办法]
integer li_FileNum

string ls_Emp_Input, ls_temp

long ll_FLength

ll_FLength = FileLength("C:\fdff\acc.txt")

li_FileNum = FileOpen("C:\fdff\acc.txt", lineMode!)

IF ll_FLength < 32767 THEN

do while FileRead(li_FileNum, ls_temp) > 0
ls_Emp_Input += ls_temp
loop

messagebox('',ls_Emp_Input)

END IF

读书人网 >PB

热点推荐