网站制作学习网ASP→正文:asp读写txt2
字体:

asp读写txt2

ASP 2010/6/15 22:31:28  点击:不统计


<%
'读取a.txt文件的文本内容
Function LoadFile(ByVal File)
  Dim objStream
  On Error Resume Next '容错
  Set objStream = Server.CreateObject("ADODB.Stream")
  If Err.Number=-2147221005 Then  '检测是否支持ADODB.Stream
    Response.Write "您的主机不支持ADODB.Stream,不能使用本程序!"
    Err.Clear
    Response.End
  End If
  With objStream
    .Type = 2
    .Mode = 3
    .Open
    .LoadFromFile Server.MapPath(File)
    If Err.Number<>0 Then
  Response.Write "文件"&File&"无法被打开,请检查是否存在!</font></div>"
  Err.Clear
  Response.End
    End If
    .Charset = "GB2312"
    .Position = 2
    LoadFile = .ReadText
    .Close
  End With
  Set objStream = Nothing
End Function
'输出内容
response.write LoadFile("a.txt")

'存储内容到a.txt文件
Sub SaveToFile(ByVal strBody,ByVal File)
  Dim objStream
  On Error Resume Next '容错
  Set objStream = Server.CreateObject("ADODB.Stream")
  If Err.Number=-2147221005 Then  '检测是否支持ADODB.Stream
    Response.Write "您的主机不支持ADODB.Stream,不能使用本程序!"
    Err.Clear
    Response.End
  End If
  With objStream
    .Type = 2
    .Open
    .Charset = "GB2312"
    .Position = objStream.Size
    .WriteText = strBody
    .SaveToFile Server.MapPath(File),2
    .Close
  End With
  Set objStream = Nothing
End Sub
'将“123456789”写入文件a.txt
SaveToFile "123456789","a.txt"
%>


转www.载for网站制作学习asp必.cn究

·上一篇:asp验证ip >>    ·下一篇:ByVal >>
推荐文章
最新文章