打开文件进行读操作,提示“输入超出了文件尾 ”,在线给分!!

Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("cc.txt",1)
f.readline
f.close

运行后出现:
Microsoft VBScript 运行时错误 错误 '800a003e'

输入超出了文件尾

/search.asp,行91

---------------------------------------------------------------

Do While Not f.AtEndOfStream
f.readline
loop
可能文件里面没内容
---------------------------------------------------------------

用f.eof来判断是否为文件结尾
---------------------------------------------------------------

来个判断:
IF f.AtEndOfStream <> true then
f.readline

End if
---------------------------------------------------------------

'使用FSO读取文件某一行的函数
function FSOlinedit(filename,lineNum)
if linenum<1 then exit function
dim fso,f,temparray,tempcnt
set fso=server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f=fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt=f.readall
f.close
set f=nothing
temparray=split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit function
else
FSOlinedit=temparray(lineNum-1)
end if
end if
end function
---------------------------------------------------------------

do until f.atendofstream
tt=tt&f.readline
loop
f.close
response.write tt

Published At
Categories with Web编程
comments powered by Disqus