我在global.asa文件中的Application_OnStart函数中有这样一段代码,用来从一个.txt文件中读出数据:
1 Const ForReading=1,ForWriting=2
2 Set fp=Server.CreateObject("Scripting.FileSystemObject")
3 counterFilePath=Server.MapPath("/counter.txt")
4 Set fpCounter=fp.OpenTextFile(counterFilePath,ForReading,TRUE)
5 Application("counter")=fpCounter.ReadLine
6 fpCounter.Close
但我每次浏览我的网页的时候,总是在第五行报错,说“输入超出文件尾”,我觉得这段代码没有问题啊,不知是什么原因?
这样写:
打开源文件
Set myFile = fso.GetFile(filePath)
Set fileReader = myFile.OpenAsTextStream(1,-2)
buffer = fileReader.ReadLine
如果要可写,就这样:
set fileWriter = myFile.OpenAsTextStream(2,-2)