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