用户登录
用户注册

分享至

asp之基于adodb.stream的文件操作类

  • 作者: 楼上老王
  • 来源: 51数据库
  • 2021-07-11
复制代码 代码如下:

<%

'*************************************************************
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'*************************************************************


'*************************************************************
'@author:                        面条
'@realname:                        徐仁禄
'@email:                        xurenlu@sohu.com
'@qq:                            55547082
'@homepage:                        http://www.51sjk.com/Upload/Articles/1/0/261/261934_20210702001934330.net
'@版权申明:
'            非盈利性质团体或者个人可以免费使用.
'*************************************************************


'*************************************************************
'        类名称:        files
'        类功能:            实现文件读写功能,利用adodb.stream实现,在不支持fso的主机上也可以读写文件.
'*************************************************************

class files


    private adsavecreateoverwrite    '创建文件的时候可以覆盖已经存在的文件.
    private adsavecreatenotexist    '保存文件的时候如果文件不存在,可以创建文件.


'*************************************************************
'        事件名称:        class_initialize()
'        事件发生条件:    类创建时候产生该事件
'        事件内容:        给私有变量赋值
'        事件传入参数:    无
'*************************************************************


    sub class_initialize()
        adsavecreateoverwrite =2
        adsavecreatenotexist = 1
    end sub


'*************************************************************
'        函数名称:        function readfile(filepath)
'        函数内容:        读出文件
'        传入参数:        filepath:要读的文件的绝对路径
'        返回参数:        要读的文件的内容.
'*************************************************************
function readfile(filepath)


    on error resume next

    dim stm2


    set stm2 =server.createobject("adodb.stream")
    stm2.charset = "gb2312"
    stm2.open
    stm2.loadfromfile filepath
    readfile = stm2.readtext
end function


'*************************************************************
'        函数名称:        function writefile(filepath,str)
'        函数内容:        写入文件
'        传入参数:        filepath:要读的文件的绝对路径
'                        str:    要写入的内容
'        返回参数:        无返回
'************************************************************* 
    function writefile(filepath,str) 
        on error resume next 
        set stm = server.createobject("adodb.stream")
        stm.charset = "gb2312"
        stm.open
        stm.writetext str
        stm.savetofile filepath, adsavecreateoverwrite
    end function



'*************************************************************
'        函数名称:        function copy(filepath_s,filepath_d)
'        函数内容:        读出文件
'        传入参数:        filepath_d:目的文件的绝对路径
'                        filepath_s:源文件路径
'*************************************************************
function copy(filepath_s,filepath_d)
    on error resume next
    dim stm2
    set stm2 =server.createobject("adodb.stream")
    stm2.charset = "gb2312"
    stm2.open
    stm2.loadfromfile filepath_s
    stm2.savetofile filepath_d, adsavecreateoverwrite
end function
end class
%>
软件
前端设计
程序设计
Java相关