How to find out the Encoding of a File? C#

后端 未结 5 923
感情败类
感情败类 2020-12-01 10:56

Well i need to find out which of the files i found in some directory is UTF8 Encoded either ANSI encoded to change the Encoding in something else i decide later. My problem

5条回答
  •  感动是毒
    2020-12-01 11:29

    http://msdn.microsoft.com/en-us/netframework/aa569610.aspx#Question2

    There is no great way to detect an arbitrary ANSI code page, though there have been some attempts to do this based on the probability of certain byte sequences in the middle of text. We don't try that in StreamReader. A few file formats like XML or HTML have a way of specifying the character set on the first line in the file, so Web browsers, databases, and classes like XmlTextReader can read these files correctly. But many text files don't have this type of information built in.

提交回复
热议问题