日期:2014-05-17  浏览次数:21025 次

一个txt 文档 1.txt,里面有500字,我如何一次把他们读出呢。赋给一个变量title1
一个txt 文档 1.txt,里面有500字,我如何一次把他们读出呢。赋给一个变量title1

------解决方案--------------------
VBScript code

    sPath = "c:\1.txt"
    Set oFM     = CreateObject("Scripting.FileSystemObject")
    If oFM.FileExists(sPath) Then
        Set oFile   = oFM.OpenTextFile(sPath, 1, False, 0)
        title1      = oFile.ReadAll()
        oFile.Close
        Set oFile   = Nothing
    End If
    Set oFM     = Nothing

------解决方案--------------------
VBScript code
Function ReadFile(url, charset)
    Dim stm
    Set stm = Server.CreateObject("ADODB.Stream")
    stm.Type = 1
    stm.Mode = 1
    stm.Open
    stm.Position = 0
    stm.LoadFromFile url
    stm.Position = 0
    stm.Type = 2
    stm.Charset = charset
    ReadFile = stm.ReadText()
    stm.Close
    Set stm = Nothing
End Function