| 范文 | 在asp读取文件中有两种方式读取文件,一种是通过fso的readall方法一种是通过adodb.stream对象的loadfromFile方法,对于两种方法详细介绍一下.
 首先看fso中的readall
 Dim fso, forasp_cn
 Set fso = CreateObject("Scripting.FileSystemObject")
 forasp_cn = fso.OpenTextFile("c:\www_forasp_cn.txt", 1)'这里1表示只读打开
 response.write forasp_cn.readall'从当前位置向后读取,直到文件结束,并将当前位置移动到文件的最后
 set forasp_cn = nothing
 上面便是fso读取一个文本内容全部内容.
 其次看adodb.stream对象的loadfromfile方法
 set srmObj = server.CreateObject("adodb.stream")
 srmObj.type=1
 srmObj.mode=3
 srmObj.open
 srmObj.Position=0
 srmObj.LoadFromFile "c:\www_forasp_cn.txt"
 srmObj.Position = 0
 srmObj.type=2
 srmObj.charset=chartype
 readfile=srmObj.readtext()
 srmObj.close
 这个是adodb.stream的读取方式
 这两个方法有什么不同FSO 不能操作二进制文件,对于大文件,使用 ReadAll 方法浪费内存资源.而adodb.stream 是二进制数据或文本的流。
 |