asp之基於adodb.stream的檔案操作類_應用技巧

來源:互聯網
上載者:User
複製代碼 代碼如下:

<%

'*************************************************************
'轉寄時請保留此聲明資訊,這段聲明不並會影響你的速度!
'*************************************************************


'*************************************************************
'@author:                        麵條
'@realname:                        徐仁祿
'@email:                        xurenlu@sohu.com
'@QQ:                            55547082
'@Homepage:                        http://www.ksdn.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
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.