网站制作学习网ASP→正文:asp中readall和loadfromfile区别
字体:

asp中readall和loadfromfile区别

ASP 2010/7/13 14:55:59  点击:不统计


在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 是二进制数据或文本的流。


http://%77%77%77%2E%66%6F%72%61%73%70%2E%63%6E

·上一篇:asp中with End with >>    ·下一篇:asp连接mysql分页问题 >>
推荐文章
最新文章