Function ReadTextFile(Path)
'Author 次碳酸钴
'This Function is useful for no BOM UTF-8
On Error Resume Next
Dim Size,Text,Charset
With CreateObject("ADODB.Stream")
.Open:.Type=1:.LoadFromFile Path
Size=.Size:If Size=0 Then Exit Function
If AscB(.Read(1))<>239 Then Size=Size+3
.Position=0:.Type=2:.Charset="UTF-8"
Err.Clear
Text=.ReadText
If Err.Number Then
Charset="Unicode"
Else
.Close:.Open
.WriteText Text
If Size<>.Size Then
Charset="GBK"
Else
Charset="UTF-8"
End If
End If
.Close:.Open:.Type=1:.LoadFromFile Path
.Position=0:.Type=2:.Charset=Charset
ReadTextFile=.ReadText
End With
End Function
'Author 次碳酸钴
'This Function is useful for no BOM UTF-8
On Error Resume Next
Dim Size,Text,Charset
With CreateObject("ADODB.Stream")
.Open:.Type=1:.LoadFromFile Path
Size=.Size:If Size=0 Then Exit Function
If AscB(.Read(1))<>239 Then Size=Size+3
.Position=0:.Type=2:.Charset="UTF-8"
Err.Clear
Text=.ReadText
If Err.Number Then
Charset="Unicode"
Else
.Close:.Open
.WriteText Text
If Size<>.Size Then
Charset="GBK"
Else
Charset="UTF-8"
End If
End If
.Close:.Open:.Type=1:.LoadFromFile Path
.Position=0:.Type=2:.Charset=Charset
ReadTextFile=.ReadText
End With
End Function