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,文件


猜你喜欢
python使用matplotlib绘制雷达图
2022-10-10 16:37:41

如何正确使用开源项目?
2023-01-29 22:14:57
Sanic框架蓝图用法实例分析
2022-12-22 16:27:20
GoFrame代码优化gconv类型转换避免重复定义map
2024-04-27 15:32:04
PHP 计算两个特别大的整数实例代码
2024-05-11 10:07:33
详解vue-amap引入高德JS API的原理
2024-06-05 09:19:31

人工智能(AI)首选Python的原因解析
2021-03-23 16:04:12

pytorch中图像的数据格式实例
2021-02-16 06:22:19
python机器人行走步数问题的解决
2023-12-24 23:26:05
pandas统计重复值次数的方法实现
2022-11-09 03:27:58
Javascript常用运算符(Operators)-javascript基础教程
2024-04-17 10:10:51
作为PHP程序员你要知道的另外一种日志
2023-11-15 02:06:59

Python读取键盘输入的2种方法
2023-03-14 22:08:37
python中的脚本性能分析
2023-10-31 00:37:22

50个常用sql语句 网上流行的学生选课表的例子
2024-01-24 10:12:23
python生成不重复随机数和对list乱序的解决方法
2023-09-24 01:17:59
Python连接mssql数据库编码问题解决方法
2024-01-24 04:41:20
python文件处理详解
2023-11-01 21:48:34
python中xlutils库用法浅析
2023-06-05 15:22:26
Pyside2中嵌入Matplotlib的绘图的实现
2021-09-15 22:34:03
