asp 读取文件和保存文件函数代码
程序员文章站
2023-08-24 11:51:19
'************************************* '读取文件 '************************************* fu...
'*************************************
'读取文件
'*************************************
function loadfromfile(byval file)
dim objstream
dim rtext
rtext = array(0, "")
set objstream = server.createobject("adodb.stream")
with objstream
.type = 2
.mode = 3
.open
.charset = "utf-8"
.position = objstream.size
on error resume next
.loadfromfile server.mappath(file)
if err then
rtext = array(err.number, err.description)
loadfromfile = rtext
err.clear
exit function
end if
rtext = array(0, .readtext)
.close
end with
loadfromfile = rtext
set objstream = nothing
end function
'*************************************
'保存文件
'*************************************
function savetofile(byval strbody, byval file)
dim objstream
dim rtext
rtext = array(0, "")
set objstream = server.createobject("adodb.stream")
with objstream
.type = 2
.open
.charset = "utf-8"
.position = objstream.size
.writetext = strbody
on error resume next
.savetofile server.mappath(file), 2
if err then
rtext = array(err.number, err.description)
savetofile = rtext
err.clear
exit function
end if
.close
end with
rtext = array(0, "保存文件成功!")
savetofile = rtext
set objstream = nothing
end function
'读取文件
'*************************************
function loadfromfile(byval file)
dim objstream
dim rtext
rtext = array(0, "")
set objstream = server.createobject("adodb.stream")
with objstream
.type = 2
.mode = 3
.open
.charset = "utf-8"
.position = objstream.size
on error resume next
.loadfromfile server.mappath(file)
if err then
rtext = array(err.number, err.description)
loadfromfile = rtext
err.clear
exit function
end if
rtext = array(0, .readtext)
.close
end with
loadfromfile = rtext
set objstream = nothing
end function
'*************************************
'保存文件
'*************************************
function savetofile(byval strbody, byval file)
dim objstream
dim rtext
rtext = array(0, "")
set objstream = server.createobject("adodb.stream")
with objstream
.type = 2
.open
.charset = "utf-8"
.position = objstream.size
.writetext = strbody
on error resume next
.savetofile server.mappath(file), 2
if err then
rtext = array(err.number, err.description)
savetofile = rtext
err.clear
exit function
end if
.close
end with
rtext = array(0, "保存文件成功!")
savetofile = rtext
set objstream = nothing
end function
上一篇: asp 数据库连接函数代码
下一篇: 根据日期得到生肖的ASP函数