Adodb.Stream 文件读写(支持UTF8等编码)
2012-05-23 金城 2628
<%
’’ASP源码
'' ADODB.Stream 读取文件
Function ReadTextFile (vPath,cs)
dim str
set stm=server.CreateObject("adodb.stream")
stm.Type=2 '以本模式读取
stm.mode=3
stm.charset=cs
stm.open
stm.loadfromfile server.MapPath(vPath)
str=stm.readtext
stm.Close
set stm=nothing
ReadUtf8File=str
End Function
'' ADODB.Stream 写入文件
Sub WriteTextFile (vPath,byval data,cs)
set stm=server.CreateObject("adodb.stream")
stm.Type=2 '以本模式读取
stm.mode=3
stm.charset=cs
stm.open
stm.WriteText data
stm.SaveToFile server.MapPath(vPath),2
stm.flush
stm.Close
set stm=nothing
End Sub
'' Adodb.Stream 转换编码
Function BytesToBstr(strBody,CodeBase)
if typename(strBody)="Empty" then
BytesToBstr=""
exit function
end if
dim objStream
set objStream = Server.CreateObject("Adodb.Stream")
objStream.Type = 1
objStream.Mode =3
objStream.Open
objStream.Write strBody
objStream.Position = 0
objStream.Type = 2
objStream.Charset = CodeBase
BytesToBstr = objStream.ReadText
objStream.Close
set objStream = nothing
End Function
%>
’’ASP源码
'' ADODB.Stream 读取文件
Function ReadTextFile (vPath,cs)
dim str
set stm=server.CreateObject("adodb.stream")
stm.Type=2 '以本模式读取
stm.mode=3
stm.charset=cs
stm.open
stm.loadfromfile server.MapPath(vPath)
str=stm.readtext
stm.Close
set stm=nothing
ReadUtf8File=str
End Function
'' ADODB.Stream 写入文件
Sub WriteTextFile (vPath,byval data,cs)
set stm=server.CreateObject("adodb.stream")
stm.Type=2 '以本模式读取
stm.mode=3
stm.charset=cs
stm.open
stm.WriteText data
stm.SaveToFile server.MapPath(vPath),2
stm.flush
stm.Close
set stm=nothing
End Sub
'' Adodb.Stream 转换编码
Function BytesToBstr(strBody,CodeBase)
if typename(strBody)="Empty" then
BytesToBstr=""
exit function
end if
dim objStream
set objStream = Server.CreateObject("Adodb.Stream")
objStream.Type = 1
objStream.Mode =3
objStream.Open
objStream.Write strBody
objStream.Position = 0
objStream.Type = 2
objStream.Charset = CodeBase
BytesToBstr = objStream.ReadText
objStream.Close
set objStream = nothing
End Function
%>