asp解决fso.ReadAll提示输入超出了文件尾的错误
来源:asp之家 时间:2008-01-30 21:40:00
最近在用fso,读取txt文本文件的内容时碰到了“输入超出了文件尾 ”的运行错误,当txt中的内容为空的时候就出现这个问题了,查了下是ReadAll的用法问题,特地转来与大家分享。
解决方法一(from:9enjoy.com)
Function getfile(filename)
dim f
if fso.fileExists(server.MapPath(filename)) then
set f = fso.OpenTextFile(server.MapPath(filename))
Response.write f.ReadAll
set f = nothing
end if
End Function
调用时出现错误:
Microsoft VBScript 运行时错误 错误 '800a003e'
输入超出了文件尾
就是Response.write f.ReadAll这句。
这是一段读取已经存在的文件,并输出文件内容的函数。但当这个文件没有内容时,就会出这种错误提示。
查了文档,ReadAll不会自己判断是否到文件尾,只好,加了个atendofstream的判断语句,测试OK。
更改后的代码为
Function getfile(filename)
dim f
if fso.fileExists(server.MapPath(filename)) then
set f = fso.OpenTextFile(server.MapPath(filename))
if not f.atendofstream then
Response.write f.ReadAll
end if
set f = nothing
end if
End Function
解决方法二( form 秋浦河畔):
Function ReadTemplate(TemplateName)
Dim objFSO,objMyFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objMyFSO = objFSO.OpenTextFile(Server.MapPath(TemplateName),1,True) '读取文本文件
ReadTemplate = objMyFSO.ReadAll&info() 'textStream对象的readAll方法,读取全部文件并返回结果字符串
objMyFSO.Close
Set objMyFSO = Nothing
Set objFSO = Nothing
End Function
如果内容不存在,则会出现“输入超出了文件尾”错误,解决方法:传递真实参数即可,或者不确定的话先判断文件是否存在再执行。
例如:
set copyss=fso.OpenTextFile(path,1)
Set f = fso.GetFile(path)
intSizeB = f.Size
if intsizeb>0 then
copystring = copyss.ReadAll
end if
标签:fso,ReadAll,文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
CSS盒模型
2009-06-09 14:23:00
![](https://img.aspxhome.com/file/UploadPic/20096/9/01-91s.png)
网站重构到底是什么
2008-11-03 11:30:00
HTML文件HEAD内部标签用法浅析
2008-07-06 20:56:00
asp如何最准确地统计在线用户数?
2010-07-11 21:12:00
有关简洁网页设计需知的6点技巧
2012-04-25 20:55:01
![](https://img.aspxhome.com/file/UploadPic/20124/25/1334557832964-88s.jpg)
主流浏览器性能比较
2009-10-19 14:34:00
![](https://img.aspxhome.com/file/UploadPic/200910/19/15-02_performance_comparison_of_web_browsers_preview-60s.jpg)
asp实现新评论自动发短信提示的代码
2011-03-07 10:38:00
MySQL数据库中对前端和后台进行系统优化
2009-01-04 13:39:00
DD_belatedPNG,解决IE6不支持PNG绝佳方案
2009-04-27 16:30:00
利用box-sizing实现div仿框架
2009-12-08 15:45:00
![](https://img.aspxhome.com/file/UploadPic/200912/8/01-32s.gif)
打败 IE 的葵花宝典:CSS Bug Table
2010-08-03 12:30:00
![](https://img.aspxhome.com/file/UploadPic/20108/3/ie_bug_table-28s.jpg)
asp中的rs.open于conn.execute的区别
2009-10-29 12:12:00
ASP自动解压RAR文件代码
2007-11-06 13:29:00
一个Access数据库数据传递的实例方法
2008-11-28 16:24:00
asp单主键高效通用分页存储过程
2009-02-23 19:21:00
oracle & mysql 多实例启动区别
2011-02-23 12:28:00
![](https://img.aspxhome.com/file/UploadPic/20112/23/2011223125046196s.jpg)
关于浏览器的一些观点
2008-08-06 12:48:00
![](https://img.aspxhome.com/file/UploadPic/20088/6/200886125027461s.gif)
Asp Oracle存储过程返回结果集的代码
2011-04-10 11:16:00
数据库主键的故事
2008-05-31 07:50:00
OL IE Bug
2009-09-09 16:25:00