VBCorLib
VBCorLib copied to clipboard
File.ReadAllText is not correct.
if file is gbk encoding, and the last char is double bytes, File.ReadAllText can't get correct string. s = File.ReadAllText("e:\aa.js", Encoding.GetEncoding("GBK"))
I found the issue, unfortunately it is not a simple fix. The problem is that the Encoder
that is being used relies on the Win32 IsDBCSLeadByteEx
method. Turns out that method can only tell you if the byte you are checking is probably a lead byte, which can lead false positives. So dependency on that method has to be removed.
If you still want to read an entire file using the encoder, it can be done using:
Dim En As Encoding
Dim Bytes() As Byte
Dim s As String
Bytes = File.ReadAllBytes("e:\aa.js")
Set En = Encoding.GetEncoding("GBK")
s = En.GetString(Bytes)