@H_502_1@
Public Function ReadFile(ByVal fileName As String) As String
@H_502_1@
If File.Exists(fileName) Then
@H_502_1@
Return File.ReadAllText(fileName,GetEncoding(fileName))
@H_502_1@
Else
@H_502_1@
Return string.Empty
@H_502_1@
End If
@H_502_1@
End Function
@H_502_1@
@H_502_1@
'
@H_502_1@
' 判断文件编码类型
@H_502_1@
'
@H_502_1@
'
@H_502_1@
'
@H_502_1@
Public Overloads Shared Function GetEncoding(ByVal fileName As String) As Encoding
@H_502_1@
Dim fs As FileStream = New FileStream(fileName,FileMode.Open,FileAccess.Read)
@H_502_1@
Dim r As Encoding = GetEncoding(fs)
@H_502_1@
fs.Close
@H_502_1@
Return r
@H_502_1@
End Function
@H_502_1@
@H_502_1@
'
@H_502_1@
' 判断文件流编码类型
@H_502_1@
'
@H_502_1@
'
@H_502_1@
@H_502_1@
Private Overloads Shared Function GetEncoding(ByVal fs As FileStream) As Encoding
@H_502_1@
Dim r As BinaryReader = New BinaryReader(fs,System.Text.Encoding.Default)
@H_502_1@
Dim ss() As Byte = r.ReadBytes(3)
@H_502_1@
r.Close
@H_502_1@
@H_502_1@
If (ss(0) >= 239) Then
@H_502_1@
BF
@H_502_1@
Return Encoding.UTF8
@H_502_1@
If ((ss(0) = 254)
_
@H_502_1@
AndAlso (ss(1) = 255)) Then
@H_502_1@
Return Encoding.BigEndianUnicode
@H_502_1@
ElseIf ((ss(0) = 255)
_
@H_502_1@
AndAlso (ss(1) = 254)) Then
@H_502_1@
Return Encoding.Unicode
@H_502_1@
Else
@H_502_1@
Return Encoding.Default
@H_502_1@
End If
@H_502_1@
Else
@H_502_1@
Return Encoding.Default
@H_502_1@
End If
@H_502_1@
End Function