Recently, I encountered a problem that my eclipse cannot correctly display Chinese characters, as shown below:
1. Read the Chinese characters of a file and output it to the console. garbled characters are found;
2. output to the console through system. Out. There is no problem, but the Chinese output to the console is re-read, garbled;
3. Enter the content in the console, and then write the content into a file.
I thought there was a problem with the Chinese encoding settings of my Eclipse, but after all the changes, I found that the problem still exists. The system also supports Chinese, and there is no problem with the settings. In this caseProgramYes. So I wrote such a simpleCode:
Bufferedreader reader =NewBufferedreader (NewInputstreamreader (system. In); system. Out. println (reader. Readline (); reader. Close ();
Check whether my console is faulty and the result is garbled. There are only two possible problems:
1. system. In has a problem;
2. There is a problem with reader. Readline.
Reader. readline () is not a problem for the time being, because bufferedreader is dedicated to reading characters, but here I have an inputstreamreader that reads bytes and occupies two bytes for Chinese characters, however, inputstreamreader reads only one byte at a time. If the number of Chinese characters is odd, garbled characters may occur.
There are many methods on the Internet, such as specifying the Chinese encoding format. I have tried it. Finally, I found a method. The test is feasible. The method is as follows:
(1) Disable eclipse;
(2)in the same directory of eclipse.exe, there is an eclipse. ini, open it, and then add the following sentence:
-Dfile. Encoding = UTF-8
Save;
(3) re-open eclipse and the problem will disappear.
-Dfile. Encoding = UTF-8, which literally means to set the system attribute file. encoding to UTF-8.