当前位置: 移动技术网 > IT编程>开发语言>Asp > asp 读取文件和保存文件函数代码

asp 读取文件和保存文件函数代码

2017年12月12日  | 移动技术网IT编程  | 我要评论
'*************************************
'读取文件
'*************************************

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网