You open a text type file (.txt, .log, etc). You know it contains some Chinese or Japanese characters. You open it and it looks a mess. Is this file damaged? Maybe not. You can change the file suffix to .html, and open it within your favorite browser. Change the character encoding to utf-8. You may be able to view it. So what is wrong?
The file is encoded in UTF-8. It needs hints to the view application such as Notepad to open it as UTF-8, not ASCII plain text. The hint is BOM (Byte Order Mark). For UTF-8, the BOM is "ef bb bf". When you save a file in UTF-8 in Windows Notepad, it actually inserts this BOM at the beginning. In case you generate this file in other ways, you can insert the BOM on your own.
putc(0xef, traceFile);putc(0xbb, traceFile); putc(0xbf, traceFile);
The file is encoded in UTF-8. It needs hints to the view application such as Notepad to open it as UTF-8, not ASCII plain text. The hint is BOM (Byte Order Mark). For UTF-8, the BOM is "ef bb bf". When you save a file in UTF-8 in Windows Notepad, it actually inserts this BOM at the beginning. In case you generate this file in other ways, you can insert the BOM on your own.
putc(0xef, traceFile);putc(0xbb, traceFile); putc(0xbf, traceFile);
Comments
Post a Comment