Yesterday I made a software program for memorizing words, in which system. Io was used to read Word files. However, when streamreader sr = new streamreader (filename); is used, when Sr. Readline (); is output, all Chinese characters in the file are garbled. So I found a solution on the Internet and finally found the cause:
Reference: (from yijiemei)
******
The reason is that since Windows 2000 and later operating systems use Unicode by default during file processing, the default file encoding for. NET is also Unicode. Unless otherwise specified, streamreader is encoded as Unicode by default, rather than ANSI of the current system.CodePage. However, most documents are still stored in ANSI encoding, and Chinese text uses gb2312, which causes Chinese garbled characters. That is to say, you must specify the encoding format when reading the text.
******
The solution is system. Text. encoding. default.
Streamreader can be encoded in the current operating system.
Streamreader reader = new streamreader (filename, system. Text. encoding. Default)