11
4

5 回答 5

6

If the file only contains these three bytes, then there is no information at all about which encoding to use.

A byte is just a byte, and there is no way to include any encoding information in it. Besides, the hex editor doesn't even know that you intended to decode the data as text.

Notepad normally uses ANSI encoding, so if it reads the file as UTF-8 then it has to guess the encoding based on the data in the file.

If you save a file as UTF-8, Notepad will put the BOM (byte order mark) EF BB BF at the beginning of the file.

于 2011-07-20T22:44:11.657 回答
3

Notepad makes an educated guess. I don't know the details, but loading the first few kilobytes and trying to convert them from UTF-8 is very simple, so it probably does something similar to that.

于 2011-07-20T22:44:22.857 回答
2

...and sometimes it gets it wrong... https://ychittaranjan.wordpress.com/2006/06/20/buggy-notepad/

于 2011-07-21T09:57:34.290 回答
2

There is an easy and efficient way to check whether a file is in UTF-8. See Wikipedia: http://en.wikipedia.org/w/index.php?title=UTF-8&oldid=581360767#Advantages, fourth bullet point. Notepad probably uses this.

Wikipedia claims that Notepad used the IsTextUnicode function, which checks whether a patricular text is written in UTF-16 (it may have stopped using it in Windows Vista, which fixed the "Bush hid the facts" bug): http://en.wikipedia.org/wiki/Bush_hid_the_facts.

于 2013-11-13T17:22:23.500 回答
0

how to identify the file is in which encoding ....?

Go to the file and try to Save As... and you can see the default (current) encoding of the file (in which encoding it is saved).

于 2015-12-23T09:57:12.283 回答