当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP教程:读取文件和写文件

ASP
JS复制特定内容到粘贴板
ASP+Access数据库安全设置方法小结
ADSI+ASP添加IP到IIS禁止访问列表中
ASP Google的translate API代码
最小asp后门程序
asp xml 缓存类
asp 过滤尖括号内所有内容的正则代码
ASP去掉字符串头尾连续回车和空格的Function
ASP IE地址栏参数的判断
SQL 注入式攻击的终极防范
ASP也使用ORM,给ASP上所有的SQL注入画上句号
判断Session的过期时间 采用JavaScript实时显示剩余多少秒
asp 动态生成rss(不成生xml文件)代码
ASP XML制作菜单管理程序
asp之自动闭合HTML/ubb标签函数附简单注释
asp 读取文件和保存文件函数代码
asp 随机字符串函数
asp form 表单验证函数
ASP 循环导入导出数据处理 不使用缓存
asp 数据库连接函数代码

ASP教程:读取文件和写文件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 58 ::
收藏到网摘: n/a

读取文件操作:

'-------------------------------------------------
'函数名称:ReadTextFile
'作用:利用AdoDb.Stream对象来读取UTF-8格式的文本文件
'----------------------------------------------------
Function ReadFromTextFile (FileUrl,CharSet)
    dim str
    set stm=server.CreateObject("adodb.stream")
    stm.Type=2 '以本模式读取
    stm.mode=3
    stm.charset=CharSet
    stm.open
    stm.loadfromfile server.MapPath(FileUrl)
    str=stm.readtext
    stm.Close
    set stm=nothing
    ReadFromTextFile=str
End Function

写文件操作:

'-------------------------------------------------
'函数名称:WriteToTextFile
'作用:利用AdoDb.Stream对象来写入UTF-8格式的文本文件
'----------------------------------------------------
Sub WriteToTextFile (FileUrl,byval Str,CharSet)
    set stm=server.CreateObject("adodb.stream")
    stm.Type=2 '以本模式读取
    stm.mode=3
    stm.charset=CharSet
    stm.open
        stm.WriteText str
    stm.SaveToFile server.MapPath(FileUrl),2
    stm.flush
    stm.Close
    set stm=nothing
End Sub

创建一个config.asp的文件

call WriteToTextFile("config.asp","谁是最可爱的人","utf-8")