用ASP读取/写入UTF-8编码格式的文件
程序员文章站
2023-11-07 11:57:40
<% '------------------------------------------------- '函数名称:readtextfile '作用:利用adod...
<%
'-------------------------------------------------
'函数名称: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
%>
<%
dim strtext
strtext = readfromtextfile ("test_utf-8.txt","utf-8")
%>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<head>
<title> 代码实例:用asp读取/写入utf-8编码格式的文件 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="author" content="枫岩,cnlei.y.l@gmail.com">
<meta name="copyright" content="http://www.cnlei.com" />
</head>
<body>
<%=strtext%>
</body>
</html>
'-------------------------------------------------
'函数名称: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
%>
<%
dim strtext
strtext = readfromtextfile ("test_utf-8.txt","utf-8")
%>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<head>
<title> 代码实例:用asp读取/写入utf-8编码格式的文件 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="author" content="枫岩,cnlei.y.l@gmail.com">
<meta name="copyright" content="http://www.cnlei.com" />
</head>
<body>
<%=strtext%>
</body>
</html>