给你两个函数,一个写入,一个读出,一次完成:
- '将文本文件读到字符串中
- Function ReadFromFile(FileName As String) As String
- Dim objFSO
- Dim fdata
- Dim objCountFile
- Err.Clear
- On Error Resume Next
- Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
- Set objCountFile = objFSO.OpenTextFile(FileName, 1, True)
- If Not objCountFile.AtEndOfStream Then fdata = objCountFile.ReadAll
- objCountFile.Close
- Set objCountFile = Nothing
- Set objFSO = Nothing
- If Err.Number <> 0 Then
- ReadText = fdata
- Else
- ReadText = fdata
- End If
- End Function
- '将字符串写入到文本文件中
- Function WriteToFile(FileName As String, fdata As String) As Boolean
- Dim objFSO
- Dim objCountFile
- Err.Clear
- On Error Resume Next
- Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
- Set objCountFile = objFSO.CreateTextFile(FileName, True)
- objCountFile.Write fdata
- objCountFile.Close
- Set objCountFile = Nothing
- Set objFSO = Nothing
- If Err.Number <> 0 Then
- WriteText = False
- Else
- WriteText = True
- End If
- End Function
|