<%
'讀取a.txt文件的文本內(nèi)容
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
'輸出內(nèi)容
response.write LoadFile("a.txt")
'存儲內(nèi)容到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"
%>
更多信息請查看IT技術(shù)專欄