asp伪静态情况下实现的utf-8文件缓存实现代码(2)


'Retrieval.Open "GET",url,false,"",""
'Retrieval.Send
'getHTTPPage = Retrieval.ResponseBody
'Set Retrieval = Nothing
End Function
Sub WriteFile(filePath)
dim stm
set stm=Server.CreateObject("adodb.stream")
stm.Type=2 'adTypeText,文本数据
stm.Mode=3 'adModeReadWrite,读取写入,此参数用2则报错
stm.Charset="utf-8"
stm.Open
stm.WriteText list
stm.SaveToFile Server.MapPath(filePath),2 'adSaveCreateOverWrite,文件存在则覆盖
stm.Flush
stm.Close
set stm=nothing
End Sub

Function ReadFile(filePath)
dim stm
set stm=Server.CreateObject("adodb.stream")
stm.Type=1 'adTypeBinary,按二进制数据读入
stm.Mode=3 'adModeReadWrite ,这里只能用3用其他会出错
stm.Open
stm.LoadFromFile Server.MapPath(filePath)
stm.Position=0 '把指针移回起点
stm.Type=2 '文本数据
stm.Charset="utf-8"
ReadFile = stm.ReadText
stm.Close
set stm=nothing
End Function
'检测文件是否存在
Function ReportFileStatus(FileName)
set fso = server.createobject("scripting.filesystemobject")
if fso.fileexists(FileName) = true then
ReportFileStatus=true
else
ReportFileStatus=false
end if
set fso=nothing
end function
'检测目录是否存在
function tesfold(foname)
set fs=createobject("scripting.filesystemobject")
filepathjm=server.mappath(foname)
if fs.folderexists(filepathjm) then
tesfold=True
else
tesfold= False
end if
set fs=nothing
end function
'建立目录
sub createfold(foname)
set fs=createobject("scripting.filesystemobject")
fs.createfolder(foname)
set fs=nothing
end sub
'删除文件
function del_file(path) 'path,文件路径包含文件名
set objfso = server.createobject("scripting.FileSystemObject")
'path=Server.MapPath(path)
if objfso.FileExists(path) then '若存在则删除
objfso.DeleteFile(path) '删除文件
else
'response.write "<script language='Javascript'>alert('文件不存在')</script>"
end if
set objfso = nothing
end function
%>