Asp读写UTF-8格式文件

canca canca
2010-02-18 01:08
1
0






  1. '-------------------------------------------------
  2. '函数名称:ReadTextFile
  3. '作用:利用AdoDb.Stream对象来读取UTF-8格式的文本文件
  4. '----------------------------------------------------
  5. function ReadFromTextFile (FileUrl,CharSet)
  6.     dim str
  7.     set stm=server.CreateObject("adodb.stream")
  8.     stm.Type=2 '以本模式读取
  9.     stm.mode=3 
  10.     stm.charset=CharSet
  11.     stm.open
  12.     stm.loadfromfile server.MapPath(FileUrl)
  13.     str=stm.readtext
  14.     stm.Close
  15.     set stm=nothing
  16.     ReadFromTextFile=str
  17. end function
  18. '-------------------------------------------------
  19. '函数名称:WriteToTextFile
  20. '作用:利用AdoDb.Stream对象来写入UTF-8格式的文本文件
  21. '----------------------------------------------------
  22. Sub WriteToTextFile (FileUrl,byval Str,CharSet)        
  23.     set stm=server.CreateObject("adodb.stream")
  24.     stm.Type=2 '以本模式读取
  25.     stm.mode=3
  26.     stm.charset=CharSet
  27.     stm.open
  28.     stm.WriteText str
  29.     stm.SaveToFile server.MapPath(FileUrl),2    
  30.     stm.flush
  31.     stm.Close
  32.     set stm=nothing
  33. end Sub

发表评论