asp 读取 utf-8格式文档并生成utf-8格式文档的乱码(2)
stm.Type=2 'adTypeText,文本数据
stm.Mode=3 'adModeReadWrite,读取写入,此参数用2则报错
stm.Charset=CharSet
stm.Open
stm.WriteText fileContent
stm.SaveToFile filePath,2 'adSaveCreateOverWrite,文件存在则覆盖
stm.Flush
stm.Close
set stm=nothing
End Sub
'要读取的文件路径
read_path = Server.MapPath("example.xml")
'要写入的文件路径
write_path = Server.MapPath("example.asp")
'读取的文件内容
content = ReadTextFile(read_path,"utf-8")
'输出读取的文件
Response.Write(content)
'开始写入
call WriteTextFile(write_path,content,"utf-8")
%>
这段代码相当实用,对于生成utf-8格式静态页十分有用,一些必要的解释我也注明了,需要注意的是:
复制代码 代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.CodePage=65001%>
<% Response.Charset="UTF-8" %>